Here's my code:
function display_name1($s){
global $db;
$query1 = 'SELECT Name From Drink where P_Key = $s';
$r = $db->prepare($query1);
$r->execute();
$result = $r->fetchColumn();
return $result;
}
$s contains the result returned from the P_Key, an auto incremented column. I want to be able to give the query the P_Key and it will return whatever variable from that row I want. For some reason, this isn't working. It returns nothing. Now if I return $s, then it does display the numbers like it should, so the problem isn't with the $s variable itself. If I take the $s out of the query, and replace it with a number, then it returns the name of the drink just like it should, so the problem isn't with the database or the query. The problem seems to be that $s is being interpreted incorrectly.
I've tried converting it to an integer ahead of putting it into the query, no dice. Any ideas?