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
– César Sousa
var_dum() performed array(3) { ["user_id"]=> NULL ["name"]=> NULL ["user_photo"]=> NULL
– César Sousa
Excuse my inattention, Caesar! You better do the
var_dump()
in the variable$row
.– felipe.zkn
If possible, also do it in the variable
$sql
to make sure that the query is being well mounted.– felipe.zkn
You started the session with
session_start
?– rray
yes I started session_start var_dum() in the $Row variable returns NULL and $sql variable Returns the query well mounted.
– César Sousa
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()
?– felipe.zkn
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?
– felipe.zkn
Another possibility is that the return of the encrypted password is different from what is recorded in the database.
– felipe.zkn
Link to database is ok so I checked the query returned in mysql and returns a line corresponding to user who was logging in
– César Sousa
I pasted the body of the function ligarbd() above in the post
– César Sousa
mysql_num_rows($query)
returns 1?– felipe.zkn
mysql_num_rows($query) yes returns 1
– César Sousa