2
$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)

1
  • 1
    can you show us db error? $db - what is it? is it third party component? it must have some method to retrieve last sql error. Commented Mar 28, 2011 at 8:41

3 Answers 3

5

by and on are MySQL reserved words.

Try enclosing them in back-ticks.

Sign up to request clarification or add additional context in comments.

2 Comments

Aha. Thank you. I need to enclose them in `, right? Or do I have to rename the values in the table?
Enclose them in backticks, you don't have to rename them.
1

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)

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.