Here's my code:
$gid = (int) stripslashes($_POST['id']);
echo $gid;
$db = dbConnect();
$test = $db->query('update games set played = played + 1 where id = "$gid"');
echo $db->error;
echo $db->errno;
die();
}
It works fine from the terminal, and it correctly prints out $gid, and no errors are returned. Am I missing something really obvious?
anything in single quotes is not parsed. do
id="' . $gid . '"
alternatively wrap the entire thing in double quotes and put single quotes around $gid.
try
You are enclosing the query in single quotes. And in single quotes variable interpolation(also called substitution) does not happen.
Simple example:
Change your code as:
Also from the line:
$gid = (int) stripslashes($_POST['id']);
its clear that$gid
is an integer and there is not need to enclose it in quotes in your query. So we have: