This topic is locked

Save old data record in another table

7/3/2010 4:28:16 AM
PHPRunner General questions
D
drk2009 author

Hello,

Can anyone please help me fix my code, I am getting a systax error on my code and I can't find what is wrong with it.



//********** Save old data record in another table ************

global $conn,$strTableName;
$strSQLSave = "INSERT INTO condition_archive (`ID`,

`Name`, `Date_Entered`, `Date_modified`, `Created_by`, `Description`, `Description1`,

`Description2`, `Description3`, `Assign_to`, `Compliant`, `Action_required`) SELECT `ID`,

`Name`, `Date_Entered`, `Date_modified`, `Created_by`, `Description`, `Description1`,

`Description2`, `Description3`, `Assign_to`, `Compliant`, `Action_required`

FROM ".$strTableName." where ".$where;

db_exec($strSQLSave,$conn);
return true;


I am getting the following error:



Technical information

Error type 256

Error description 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 'condition where ID=1' at line 6

URL localhost/phprunner/condition_edit.php?

Error file C:\wamp\www\phprunner\include\dbconnection.php

Error line 36

SQL query INSERT INTO condition_archive (ID, Name, Date_Entered, Date_modified, Created_by, Description, Description1, Description2, Description3, Assign_to, Compliant, Action_required) SELECT ID, Name, Date_Entered, Date_modified, Created_by, Description, Description1, Description2, Description3, Assign_to, Compliant, Action_required FROM condition where ID=1


Any help will be appreciated.
Sincerely,

Derek P

Sergey Kornilov admin 7/3/2010

CONDITION is a reserved word in MySQL (More info: http://www.htmlite.com/mysql002a.php).
You can either rename this table or add backtics to table name in SQL query manually:

//********** Save old data record in another table ************

global $conn,$strTableName;
$strSQLSave = "INSERT INTO condition_archive (`ID`,

`Name`, `Date_Entered`, `Date_modified`, `Created_by`, `Description`, `Description1`,

`Description2`, `Description3`, `Assign_to`, `Compliant`, `Action_required`) SELECT `ID`,

`Name`, `Date_Entered`, `Date_modified`, `Created_by`, `Description`, `Description1`,

`Description2`, `Description3`, `Assign_to`, `Compliant`, `Action_required`

FROM `".$strTableName."` where ".$where;

db_exec($strSQLSave,$conn);
return true;
D
drk2009 author 7/3/2010

Hello
Thank you Sergey,
Very much appreciated, I rename the tables and it is working fine.
Sincerely,

Derek Popovich