You need to add to your code the binding of the result to a specific variable
$emailsql->bind_result($emailResult);
And you fetch it :
while($emailsql->fetch()){
printf ($emailResult);
}
So this should be it:
$emailsql = $conn->prepare("SELECT email FROM User WHERE email = ? limit 1;");
$emailsql->bind_param('s', $email);
$emailsql->execute();
$emailsql->bind_result($emailResult);
while($emailsql->fetch()){
printf ($emailResult);
}
In case you need the variable outside the loop I would take this approach:
$theEmail;
$emailsql = $conn->prepare("SELECT email FROM User WHERE email = ? limit 1;");
$emailsql->bind_param('s', $email);
$emailsql->execute();
$emailsql->bind_result($emailResult);
while($emailsql->fetch()){
$theEmail=$emailResult;
}
Note that you would need an array in order to query more than one email.
Another cleaner approach as @YourCommonSense suggested would be avoiding the loop like so:
$theEmail;
$emailsql = $conn->prepare("SELECT email FROM User WHERE email = ? limit 1;");
$emailsql->bind_param('s', $email);
$emailsql->execute();
$emailsql->bind_result($emailResult);
$emailsql->fetch();
printf($emailResult);
->
to show or assign value to a variable – SayJeyHi May 9 '16 at 13:18var_dump($emailsql)
? – Doxmare May 9 '16 at 13:18