I'm trying to retrieve the email
field from my database using the id
associated with it:
$query2 = mysql_query("SELECT email FROM `users` WHERE `id` = '".$userID."' ") or die(mysql_error());
This query is always returning NULL
and I can't work out why.
Have tested using a var_dump
that $userID
is indeed correct.
But when I use it with the hardcoded value instead of $userID
it works fine:
$query2 = mysql_query("SELECT email FROM `users` WHERE `id` = '85' ") or die(mysql_error());
Why isn't the $userID
variable being passed to my query? Is there a way to pass this correctly?
Edit:
Declaration of $userID as requested. var_dump of this variable works OK the line before the query2.
// Fetch ID for matching details
$query = mysql_query("SELECT id FROM `users` WHERE `email` = '".$emailInput."' && `username` = '".$usernameInput."' ") or die(mysql_error());
// Successful query - ID stored
if(mysql_num_rows($query) > 0){
$userID = mysql_fetch_array($query);}
var_dump($userID);
Both var_dumps output the following on the page:
array(2) { [0]=> string(2) "85" ["id"]=> string(2) "85" } NULL