This topic is locked

Before Record Add

3/2/2008 5:44:03 PM
PHPRunner General questions
J
jackel66 author

Ok i have one last problem with this that i cant seem to get to work right.
Im trying to add from one page to 2 tables using the Before record add. Code looks like :
$strSQLSave = "INSERT INTO comments1archive (`User`, `Project`, `Comment`, `Req`, `Date`) values (";
$strSQLSave .= $values["`User`"].",";

$strSQLSave .= $values["`Project`"].",";

$strSQLSave .= $values["`Comment`"].",";

$strSQLSave .= $values["`Req`"].",";

$strSQLSave .= $values["`Date`"];
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
But when i exec the code i get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,)' at line 1
I have tried several variations of this without ` and with but it will take the value being added at the column name i know im probably missing the obvious solution but i could use a little help if anyone can.
thanks

A
alang 3/2/2008

The backquote ` is used in SQL statement but not inside a PHP statement. Use the normal quote ' around values. Also for debugging something like this, output the final string ($strSQLSave ) using echo etc and this will often give you a better idea of what is happening especially if you can use that string to test in another program like SQLyog. I would suggest:
$strSQLSave = "INSERT INTO comments1archive (`User`, `Project`, `Comment`, `Req`, `Date`) values (";

$strSQLSave .= "'".$values["User"]."',";

$strSQLSave .= "'".$values["Project"]."',";

$strSQLSave .= "'".$values["Comment"]."',";

$strSQLSave .= "'".$values["Req"]."',";

$strSQLSave .= "'".$values["Date"]."'";

$strSQLSave .= ")";

db_exec($strSQLSave,$conn);