Forum Moderators: coopster
function replaceQuestion($lvl, $ques, $a, $b, $c, $d, $ans, $nr) {
$qu="UPDATE '$lvl'
SET ques = '$ques', a = '$a', b = '$b',
c = '$c', d = '$d', ans='$ans'
WHERE nr = '$nr'
";
mysql_query($qu);
}
Regards
[edited by: SoulMaster at 10:31 pm (utc) on May 28, 2008]
$link = mysql_connect('localhost', 'username', 'password');
#
#
function replaceQuestion($lvl, $ques, $a, $b, $c, $d, $ans, $nr) {
#
#then grab that variable in your function
global $link;
#
$qu= [url=http://www.php.net/sprintf]sprintf[/url]("UPDATE `%s` SET `ques` = '%s', `a` = '%s', `b` = '%s', `c` = '%s', `d` = '%s', `ans`='%s' WHERE `nr` = '%s'",
[url=http://www.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]($lvl),
mysql_real_escape_string($ques),
mysql_real_escape_string($a),
mysql_real_escape_string($b),
mysql_real_escape_string($c),
mysql_real_escape_string($d),
mysql_real_escape_string($ans),
mysql_real_escape_string($nr));
#
#you should know if the update was successful or not, so return the value instead
return mysql_query($qu, $link); #you might want to add error reporting, too, for debugging
}
If this doesn't work then there is something wrong with your connection to the database, or your query itself.
[edited by: eelixduppy at 3:18 pm (utc) on May 29, 2008]
'$lvl'. I have added MySQL's escape character around the table name in my example, the prime character(`). So the corrected looked like the following: `$lvl`. That fact that you didn't escape your variables wasn't the issue, it just could be a security issue, or just break your script completely.
Hope that helps for future projects :)