开发者

MySQL INSERT INTO fails silently without error

开发者 https://www.devze.com 2023-02-20 09:51 出处:网络
$dotheactvity = $db->db_exec(\"INSERT INTO activity (notification, by, on, extra, extra2) VALUES (\'$nou\', \'$nome\', \'$tehtime\', \'$herpdederp\', \'$id2\')\");
$dotheactvity = $db->db_exec("INSERT INTO activity (notification, by, on, extra, extra2) VALUES ('$nou', '$nome', '$tehtime', '$herpdederp', '$id2')");

For some reason, this query just fails without warning. Everything else works, bu开发者_StackOverflow中文版t not this line. I checked, and all the variables exist. I can't seem to find anything in logs, either.

(please excuse my immaturity in naming my arguments)


by and on are MySQL reserved words.

Try enclosing them in back-ticks.


Try this:

$sql = "INSERT INTO activity (notification, by, on, extra, extra2) VALUES ('".$nou."', '".$nome."', '".$tehtime."', '".$herpdederp."', '".$id2."')";

Possible reason why this would work is that your values might be string values which need to be enclosed in quotation marks.

So, when MySQL reads your SQL, it will look like this:

INSERT INTO activity (notification, by, on, extra, extra2) VALUES ('val1', 'val2', 'val3', 'val4', 'val5');


You can check your SQL statement's formatting using

echo $sql;

or

print_r($sql);

or

var_dump($sql)


Normally I will put the query string in a variable first, then will echo it out (just for debugging). It will be clearer and easier to spot the error. and also, you can copy and paste the query and run in the mysql console or phpmyadmin query console. It will tell you the error from there.

$sql = "INSERT INTO activity (notification, by, on, extra, extra2) VALUES ('$nou', '$nome', '$tehtime', '$herpdederp', '$id2')";
echo $sql;
0

精彩评论

暂无评论...
验证码 换一张
取 消