CrazyEngineers Forum

******************************************
Join CE! | CE Innovator Contest! | Forgot password?
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  #1 (permalink)
Old 2nd July 2008, 06:59 PM
hbk
CE - Apprentice
 
I'm a Crazy Computers Engineer
Join Date: 12th June 2008
Posts: 36
Default Updating multiple columns in single MySQL table

hey guys...

i know this is a very common problem and has been posted earlier also... but nobody seems to have figured out a solution...

i am making a program using PHP/MySQL.

I need to update 3 columns in a table. when i use a single UPDATE-SET command(using commas/AND etc etc.... i've tried them all).. only the first field gets updated, the other 2 remaining as they are.

When i use three seperate UPDATE commands, one for each column, FUNNILY, the first and the third columns get updated, and for some GOD KNOWS WHAT reason, the second column just refuses to change...

the code is correct and is infact the same for all 3 statements (with the "field_name" beng different of course..)


please help as this is really bugging...

thx..
__________________
2 ways to happines--->

1. Accept what you cannot change
2, Change what you cannot accept
hbk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 4th July 2008, 08:41 AM
CEan - Value Adder
 
kidakaka's Avatar
 
I'm a Crazy Computer Science Engineer
Join Date: 18th October 2006
Location: Mumbai, Hyderabad
Posts: 446
Send a message via AIM to kidakaka Send a message via MSN to kidakaka Send a message via Yahoo to kidakaka Send a message via Skype™ to kidakaka
Default Re: updating multiple columns in single MySQL table

Hi hbk,
Are you checking the code for exclusive table and field locks?
Do you have any other processes/triggers (mysql5 does have them) that update/revert the values back?
Are you using manual transaction processing, and committing the transaction half way through?

Would certainly help if you could post the code here or mail it to me - prasad dot ajinkya at gmail dot com.
kidakaka is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 6th July 2008, 08:18 PM
hbk
CE - Apprentice
 
I'm a Crazy Computers Engineer
Join Date: 12th June 2008
Posts: 36
Default Re: updating multiple columns in single MySQL table

here is the code---

mysql_query("UPDATE table SET dod = '$dod' where ID = '$id' ");

mysql_query("UPDATE table SET mod = '$mod' where ID = '$id' ");

mysql_query("UPDATE table SET yod = '$yod' where ID = '$id' ");


the 1st and the 3rd query get executed, but no updation occurs thru the 2nd query.

I have even tried using a single query, but the same effect.

When i use mysql_error() with the second query, it reports the error --

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 'mod = '10' ,yod='2008' where ID =56 at line 1.


Somebody please help...

thx a ton...
__________________
2 ways to happines--->

1. Accept what you cannot change
2, Change what you cannot accept
hbk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 1st August 2008, 04:56 PM
CE - Newbie
 
I'm a Crazy Sofware Engineer
Join Date: 1st August 2008
Posts: 1
Smile Re: updating multiple columns in single MySQL table

Quote:
Originally Posted by hbk View Post
here is the code---

mysql_query("UPDATE table SET dod = '$dod' where ID = '$id' ");

mysql_query("UPDATE table SET mod = '$mod' where ID = '$id' ");

mysql_query("UPDATE table SET yod = '$yod' where ID = '$id' ");


the 1st and the 3rd query get executed, but no updation occurs thru the 2nd query.

I have even tried using a single query, but the same effect.

When i use mysql_error() with the second query, it reports the error --

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 'mod = '10' ,yod='2008' where ID =56 at line 1.


Somebody please help...

thx a ton...

Hi hbk,
I don’t know if it’s too late posting this, you might already have figured it out. When it comes to mysql, in your queries you must be careful when you want to update or insert data into columns with names that are usual parameters in mysql statements. For e.g ifyou want to update a column named update you must escape it with `, like UPDATE news set `update`=’value’. In this case the column mod, you must escape it with `. Like this

mysql_query("UPDATE table SET dod = '$dod', `mod`=’$mod’, yod =’$yod’ where ID = '$id' ");



Good luck

________________________
ILLUMINA
Web Dev Swe

Last edited by mbz-bugsy : 1st August 2008 at 05:22 PM.
mbz-bugsy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 06:40 AM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger