$connection = mysql_connect($host,$user,$pass) or die ("ERROR:Unable to connect".mysql_error());
mysql_select_db($db) or die ("ERROR: Unable to connect to DB".mysql_error());
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
foreach ($_POST as $id => $rating){
if ($id == 'submit') {
exit();
} //exits when it gets to submit
$update_table =sprintf("
UPDATE menu
SET rating = rating + %s
, number_of_votes = number_of_votes + 1
WHERE id = %s",
quote_smart($rating),
quote_smart($id));
$result = mysql_query($update_table) or die(mysql_error("Query: ".$update_table." failed"));
}
I have a thread in General Help because i was having problems building my rating system and someone gave a solution with this coding but i do not understand what it is doing. For example where does the %s value come from. I know it outputs the value as a string but from where?
Can someone help.
Thanks