Mysql "UPDATE" isn't doing anything
This is my code for the update:
$k开发者_C百科ey = $skills[$ind];
echo "\t\t<td>" . $key . "</td>\n";
//explode using a comma as a delimiter
$data_n = explode(",", $word);
$score[$key][”Rank”] = $data_n[0];
$score[$key][”Level”] = $data_n[1];
$score[$key][”Exp”] = $data_n[2];
echo "\t\t<td>" .$data_n[0] . "</td>\n";
echo "\t\t<td>" .$data_n[1] . "</td>\n";
echo "\t\t<td>" .$data_n[2] . "</td>\n";
$result = mysql_query("UPDATE accounts SET $key ='$data_n[1]' WHERE username = '$user'")
or
die(mysql_error());
Basically, there's a string "key" that is the name of the thing I'm trying to update, but it's just not updating. I've changed "mysql_query" to "print" and it prints out exactly what it's supposed to:
UPDATE accounts SET Total ='1144' WHERE username = 'derekboy'
There aren't any errors. printing out $result shows that it's "True" that it sent the message to MySQL. Can anyone see the problem, because I've been looking for a whole day and still nothing.
All of my code is located here; thanks. You can see that I connect to a database at the very top of the script.
1) You does not seem to have connected to mysql. Does your code do mysql_connect
and mysql_select_db
prior to this ?
2) Try running the query in the PHPMyAdmin (or whatever MySQL client you use) to see if there's any error or not. Does the query runs fine there ?
3) Most probably, there is no username
with value derekboy
in your table.
I don't know PHP particularly well, but it seems that you are surrounding the variables with single quotes, in which variables aren't interpolated.
Try something like:
$result = mysql_query("UPDATE accounts SET " . $key . " ='" . $data_n[1] . "' WHERE username = '". $user" . "'") or die(mysql_error());
精彩评论