EmmanuelCorrea Posted June 7, 2018 Share Posted June 7, 2018 Good day community. With a doubt that I could not find a solution. I'm trying to log in, I have my user and my password registered (so the user does exist), but at the time of entering, he only sends me a Resource id # 51, I clarify that this is under a server, I have my bd too hosted on host, all right. Also, I do this function in localhost and I login correctly. I came across this "error" or result already when it was on the host of the server to which I do not know what is due. This is my code. $sql = sprintf("SELECT * FROM usuario WHERE usuario = '%s' AND contrasena = '%s' ", mysql_real_escape_string($usuario), mysql_real_escape_string($contrasena)); $query=mysql_query($sql); //echo mysql_errno().":".mysql_error(); echo $query; $verificar=mysql_num_rows($query); echo $verificar; if($verificar==1){ //El logueo es exitoso y se crea la sesion if($valores = mysql_fetch_assoc($query)){ if($valores['puesto'] == 'A'){ $_SESSION['usuario'] = $usuario; //header("HTTP/1.1 302 Moved Temporarily"); //header("Location: ../indexMenu.php"); }else if($valores['puesto'] == 'B'){ $_SESSION['alumno'] = $usuario; header("HTTP/1.1 302 Moved Temporarily"); header("Location: ../../../alumnos/php/indexMenu.php"); } }else{ echo 'No se ha podido iniciar sesion, por favor vuelva a intentarlo.'; } Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/ Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 See my reply to Spanish version. Don't double post - just the English versions please in future. Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558823 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 I could not solve it with mysqli_ Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558824 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 Don't shout at me. When your host upgrades to php 7 the code will not work with mysql_. Those functions have gone. Forget mysqli, PDO is much easier. But the advice about checking what each function returns still stands. What were you expecting "echo $query;" to output? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558825 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 What I do not know is the version of the php host, maybe you are not accepting the instruction. I have never used PDO. ---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol ---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558826 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 (edited) echo phpversion(); That will tell you the php version. You will have to move from mysql_ soon. The sooner you do the less you will have to rewrite. So it will have to be mysqli_ or PDO. As I advised, go with PDO Here is a PDO version /*********************************************************** ** PDO CONNECTION ************************************************************/ $host = '????'; $username = '????'; $password = '????'; $database = '????'; $dsn = "mysql:dbname=$database; host=$host; charset=utf8"; $db = new pdo($dsn, $username, $password, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); $stmt = $db->prepare("SELECT puesta FROM usuario WHERE usuario = ? AND contrasena = ? "); $stmt->execute( [$usuario, $contrasena] ); $verificar = $stmt->rowCount(); if($verificar==1){ //El logueo es exitoso y se crea la sesion if($valores = $stmt->fetch()){ if($valores['puesto'] == 'A'){ $_SESSION['usuario'] = $usuario; }else if($valores['puesto'] == 'B'){ $_SESSION['alumno'] = $usuario; header("HTTP/1.1 302 Moved Temporarily"); header("Location: ../../../alumnos/php/indexMenu.php"); } } } else { echo 'No se ha podido iniciar sesion, por favor vuelva a intentarlo.'; } Edited June 7, 2018 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558827 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 ---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol It marks me as a variable error and does not direct me any results. It's my professional title project and it's been almost a month without resolving. Damn it right ---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558828 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 3 minutes ago, EmmanuelCorrea said: ---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioSesotho meridionalShonaSindhiSomalíSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol Where does that come from? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558829 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 text selection error on another page, sorry Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558830 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 19 minutes ago, EmmanuelCorrea said: It marks me as a variable error and does not direct me any results. The page we are discussing, or that other page? If this page, what is the error message? 20 minutes ago, EmmanuelCorrea said: It's my professional title project So what is this project of yours? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558832 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 If it's my project for professional title, and I can not solve the problem. Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558833 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 4 minutes ago, EmmanuelCorrea said: If it's my project for professional title, and I can not solve the problem, ... Is there an end part to that partial sentence? Did you find out what version your host was using? 1 hour ago, Barand said: What were you expecting "echo $query;" to output? All you have really told me so far is you get " Resource id # 51 " output. You don't even say from which line output it, so I have to guess its that one above. If you cannot give more useful information then I cannot help. It's up to you. (I am also guessing that you have not even looked at the manual ([m]mysql_query[/m]) or you would have seen red boxes with warning text about mysql_ functions. If you are just learning, why waste your time on an out-of-date function library.) You are using session variables. Have you called session_start() at the top of the code? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558834 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 Yes, the version is 55.5.351, I attach the complete code. <?php $bd = $_POST['conn']; if($bd == 'deportiva'){ setcookie("conn","deportiva",time()+(60*60*24),"/"); }else{ setcookie("conn","cultural",time()+(60*60*24),"/"); } include("conexion.php"); session_start(); // Obtengo los datos cargados en el formulario de login. $usuario = $_POST['nomUsuario']; $contrasena = $_POST['inContra']; $sql = sprintf("SELECT * FROM usuario WHERE usuario = '%s' AND contrasena = '%s' ", mysql_real_escape_string($usuario), mysql_real_escape_string($contrasena)); //$sql = "SELECT * FROM usuario WHERE usuario = '".mysql_real_escape_string($usuario)."' AND contrasena = '".mysql_real_escape_string($contrasena)."' "; $query=mysql_query($sql); //echo mysql_errno().":".mysql_error(); echo $query; //echo phpversion(); $verificar=mysql_num_rows($query); echo $verificar; if($verificar==1){ //El logueo es exitoso y se crea la sesion if($valores = mysql_fetch_assoc($query)){ if($valores['puesto'] == 'A'){ $_SESSION['usuario'] = $usuario; //header("HTTP/1.1 302 Moved Temporarily"); //header("Location: ../indexMenu.php"); }else if($valores['puesto'] == 'B'){ $_SESSION['alumno'] = $usuario; header("HTTP/1.1 302 Moved Temporarily"); header("Location: ../../../alumnos/php/indexMenu.php"); } }else{ echo 'No se ha podido iniciar sesion, por favor vuelva a intentarlo.'; } // Redirecciono al usuario a la página principal del sitio. }else{ echo 'El usuario o el password es incorrecto, <a href="login.php">Por favor vuelva a intentarlo</a>.<br/><a href="../../../../bienvenido.php">Salir</a>.<br/> '; } ?> In fact I do not know where that instruction comes from, I do not know which line is returning it, I repeat, I work it in localhost and it makes me login perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558835 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 There are only two echo lines that might output it. Change "echo $query" to echo "QUERY: $query</br>"; and change "echo $verificar" to echo "VERIFICAR: $verificar<br>"; That should make things clearer. Did you try the PDO version? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558836 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 This returns me. QUERY: Resource id # 5 VERIFICAR: 1 If I probe PDO, but I send variable error (?). Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558840 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 I repeat, I am trying to perform a login, which in the host sends me that of resource id # 51, when working on the same project in localhost the login makes it correct and enters the next window. Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558841 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 (edited) So what is the answer to the question I asked 2 hours ago? 2 hours ago, Barand said: What were you expecting "echo $query;" to output? Quote If I probe PDO, but I send variable error (?). You need to tell me what the error message was - exactly. Edited June 7, 2018 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558842 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 No, to send me to the next page, which I have wrong in the code that does not allow it? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558843 Share on other sites More sharing options...
Barand Posted June 7, 2018 Share Posted June 7, 2018 1 hour ago, Barand said: If you cannot give more useful information then I cannot help It appears that you can not or will not help me to help you. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558844 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 I cite all the complete code, in which I'm not helping? Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558845 Share on other sites More sharing options...
EmmanuelCorrea Posted June 7, 2018 Author Share Posted June 7, 2018 How do I resolve that of the resource id #, or what should I put so that it does not send me that. Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558846 Share on other sites More sharing options...
benanamen Posted June 7, 2018 Share Posted June 7, 2018 Your Real Problem is you are using obsolete code that has been completely removed from Php and will not work at all in current versions. As mentioned, you need to use PDO with prepared statements. Here is a tutorial to get you going. https://phpdelusions.net/pdo You can also download my PDO Bumpstart Database that I wrote especially for people such as yourself to get you up and running immediately with a basic PDO setup and ease of viewing the code to learn from. https://github.com/benanamen/pdo_bumpstart_ver1.6 Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558848 Share on other sites More sharing options...
Barand Posted June 8, 2018 Share Posted June 8, 2018 In my PDO example, "SELECT puesta ..." should be "SELECT puesto ..." try session_start(); /*********************************************************** ** PDO CONNECTION ************************************************************/ $host = 'localhost'; $username = '?'; // provide your credentials $password = '?'; $database = '?'; $dsn = "mysql:dbname=$database; host=$host; charset=utf8"; $db = new pdo($dsn, $username, $password, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); /***********************************************************/ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // was data posted to the page? $usuario = $_POST['nomUsuario']; $contrasena = $_POST['inContra']; $stmt = $db->prepare("SELECT puesto FROM usuario WHERE usuario = ? AND contrasena = ? "); $stmt->execute( [$usuario, $contrasena] ); $verificar = $stmt->rowCount(); if($verificar==1){ //El logueo es exitoso y se crea la sesion if($valores = $stmt->fetch()){ if($valores['puesto'] == 'A'){ $_SESSION['usuario'] = $usuario; }else if($valores['puesto'] == 'B'){ $_SESSION['alumno'] = $usuario; header("HTTP/1.1 302 Moved Temporarily"); header("Location: ../../../alumnos/php/indexMenu.php"); } } } else { unset($_SESSION['usuario'], $_SESSION['alumno']); echo 'No se ha podido iniciar sesion, por favor vuelva a intentarlo.'; } } You can use this code to check if the session variables were set correctly echo '<pre>', print_r($_SESSION, 1), '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558856 Share on other sites More sharing options...
Barand Posted June 8, 2018 Share Posted June 8, 2018 13 hours ago, EmmanuelCorrea said: QUERY: Resource id # 5 si crees que es un error, ¿qué esperabas que mostrara? if you think it is an error, what were you expecting it to display? This is the last time I ask this. I need to know what you are trying to do Esta es la última vez que pregunto esto. Necesito saber qué estás tratando de hacer Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558857 Share on other sites More sharing options...
NotionCommotion Posted June 8, 2018 Share Posted June 8, 2018 It is good that you are including "reality" checks in your script. You can one better it by using var_dump($query). For this case, however, you will not get the clues you are looking for as mysql_query returns a resource and not an array or object where you can "see" the underlining data. Did you try using PDO? I expect you are under the gun getting this complete and I understand why you don't want to waste time, however, it really won't take you long getting it going. $query=mysql_query($sql); //echo mysql_errno().":".mysql_error(); echo $query; Quote Link to comment https://forums.phpfreaks.com/topic/307356-resource-id51/#findComment-1558860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.