Jump to content

Resource id#51


EmmanuelCorrea

Recommended Posts

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.';
    }

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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.';
    }

 

Link to comment
Share on other sites

 

---------------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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>';

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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;


 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.