Problem with SESSION in php

Asked

Viewed 111 times

1

Good staff,

I am here developing a login for my page but I have a problem that is not saving me in session the data I want can give me a help.

Code

require_once("../gtm/bd/funcoes.php");
ligarBd();  

// Verifica se houve POST e se o usuário ou a senha é(são) vazio(s)
if (isset($_REQUEST['valida']) && $_REQUEST['valida']=="ok"){
    $sql="select * from users_social where fb_email='".$_REQUEST['user']."' and password='".sha1($_REQUEST['password'])."'";
    $query = mysql_query($sql);
    if(mysql_num_rows($query)==1){
        $row=mysql_fetch_array($sql);
        session_register("user_id","nome", "user_foto");
        $_SESSION = array();
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['nome'] = $row['fb_nome'];
        $_SESSION['user_foto'] = $row['user_foto'];

        header("Location: http://sabeonde.pt/index.php");

    }
}

function ligarBd(){
    global $host, $bd, $user, $pass, $link;
    $link = mysql_connect($host, $user, $pass) or die ("Erro ao tentar abrir a base de dados". mysql_error());
    @mysql_select_db($bd);
}
  • The data well from the database

  • var_dum() performed array(3) { ["user_id"]=> NULL ["name"]=> NULL ["user_photo"]=> NULL

  • Excuse my inattention, Caesar! You better do the var_dump() in the variable $row.

  • If possible, also do it in the variable $sql to make sure that the query is being well mounted.

  • You started the session with session_start ?

  • yes I started session_start var_dum() in the $Row variable returns NULL and $sql variable Returns the query well mounted.

  • In this case, it is better to check if the connection is being well done. It can show us the body of the function ligarBd()?

  • If the connection is OK, you can check whether an equivalent query, when executed directly over the database (without the help of PHP), returns a single line?

  • 1

    Another possibility is that the return of the encrypted password is different from what is recorded in the database.

  • Link to database is ok so I checked the query returned in mysql and returns a line corresponding to user who was logging in

  • I pasted the body of the function ligarbd() above in the post

  • mysql_num_rows($query) returns 1?

  • mysql_num_rows($query) yes returns 1

Show 8 more comments

1 answer

1

Use:

$row=mysql_fetch_array($query);

instead of:

$row=mysql_fetch_array($sql);
  • 1

    +1 for being faster, hehe was writing this as an answer :).

  • @rray See how much time I spent asking questions in the comments, hehehe. Sometimes, for lack of attention, problems are simpler to solve than we think.

  • 1

    I was looking at the question before and tbm n had noticed xD rs. Nothing that a coffee break does not solve.

  • 2

    really was right in front of us thanks for helping really a coffee break sometimes and better

Browser other questions tagged

You are not signed in. Login or sign up in order to post.