Page 1 of 1

Update query.

Posted: Thu Apr 09, 2009 1:57 pm
by max_power
Hi,

I am currently working on an update statement (through an ODBC connection)that will edit a news item for me in the database, now my problem is it shows up with an syntax error with my update statement but points towards my result set.

Here is the code (bolded one is what it is having a problem with):

Code: Select all

 
else if ( $act == "edit" ) {
      {
    $id = $_POST['id'];
    $message = $_POST['message'];
    $sql = "UPDATE Table1 SET ('message') WHERE id =" . $_POST['id'];
    [b]$rs= odbc_exec($conn,$sql);[/b]
 
It is a simple table, contains only two fields (message and id and id is the primary key).

Now my delete, add and view statements work fine, not sure why this doesnt. :?

Any help will be appreciated.

PS. The connection to the db is in another php page so it is no worry (I Hope).

Re: Update query.

Posted: Thu Apr 09, 2009 2:47 pm
by max529
Hi,

In the Update staement ,dont you have to specify the field to be updated and the new value?
now you have given

Code: Select all

"UPDATE Table1 SET ('message') WHERE id =" . $_POST['id'];
but you havent given to what value the field 'message' should be updated to..i mean you have to give something like

Code: Select all

"UPDATE Table1 SET ('message'='$message' ) WHERE id =" . $_POST['id'];
Regards,
Max

Re: Update query.

Posted: Thu Apr 09, 2009 11:03 pm
by max_power
Thanks very much Max. 8)

That was the minor problem, although one little other problem was the ODBC connection requiring a @ in the result set like the following for those in the future if they have the same problem:

Code: Select all

 
$rs= @odbc_exec($conn,$sql);
 
Thanks again!