Query user PHP PDO [closed]

-7

For those who have the doubt as I had, below I'll leave the code ready, just change to your project. The code and simply know the user logged in and say the name of it in PHP PDO. If your project is by cookie will work, if it is session adapt your code to mine.

// USER NAME

$sql= "SELECT * FROM nomedasuatabela WHERE email='$login_cookie'"; 
$stmt = $conexao->prepare($sql);
$stmt->bindParam(':email', $login_cookie, PDO::PARAM_INT); 
$stmt->execute();
    
asked by anonymous 15.09.2016 / 20:27

1 answer

1

Unfortunately the query you entered is not correct; I believe that what is wanting to do there is to get an email that is in the browser cookie and passing to this method.

The most correct way would be:

$sql= "SELECT * FROM nomedasuatabela WHERE email = :email"; 
$stmt = $conexao->prepare($sql);
$stmt->bindParam(':email', $login_cookie, PDO::PARAM_STR); 
$stmt->execute();

Or

$sql= "SELECT * FROM nomedasuatabela WHERE email = ?"; 
$stmt = $conexao->prepare($sql);
$stmt->bindParam(1, $login_cookie, PDO::PARAM_STR); 
$stmt->execute();

I'm assuming the email there is a string.

    
15.09.2016 / 22:26