iamandrus
iamandrus

Reputation: 1430

MySQL INSERT INTO fails silently without error

$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, but 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)

Upvotes: 2

Views: 5200

Answers (3)

Goliath
Goliath

Reputation: 11

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)

Upvotes: 1

Sufendy
Sufendy

Reputation: 1242

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;

Upvotes: 0

codaddict
codaddict

Reputation: 454960

by and on are MySQL reserved words.

Try enclosing them in back-ticks.

Upvotes: 5

Related Questions