Update query.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
max_power
Forum Newbie
Posts: 5
Joined: Thu Apr 09, 2009 1:50 pm

Update query.

Post 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).
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: Update query.

Post 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
max_power
Forum Newbie
Posts: 5
Joined: Thu Apr 09, 2009 1:50 pm

Re: Update query.

Post 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!
Post Reply