for some reason, when I include $str variable in the mysql_query function, i get this error: 1054:Unknown column 'happy' in 'where clause'
BUT
when I replace $str in the mysql function with it's defined string 'happy' it runs OK.
ex. ....WHERE username = 'happy'.....
output:
1
Record found
can anyone see why I can't use variables in mysql_query function?
$str= 'happy';
$query = mysql_query("SELECT record_id FROM php_exercise2 WHERE username = $str") or die(mysql_errno() . ':' . mysql_error() ."\n");
$num_row = mysql_num_rows($query);
echo $num_row . "\n";
if (mysql_num_rows($query)==0) {
echo "No Record";
}else{
echo "Record found";
}