updating multiple columns in single MySQL table

Reply

Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

updating multiple columns in single MySQL table

 
0
  #1
Jul 2nd, 2008
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..
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,681
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 319
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: updating multiple columns in single MySQL table

 
0
  #2
Jul 2nd, 2008
Huh.. Can you post your code ? (because I have never heard of this problem before!)
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: updating multiple columns in single MySQL table

 
0
  #3
Jul 2nd, 2008
Hello,
the update command looks like this:
UPDATE tbl_name SET col1='value1', col2='value2', col3='value3'
WHERE some conditions comes here
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: updating multiple columns in single MySQL table

 
0
  #4
Jul 2nd, 2008
hi silviuks

i tried the method u suggested, but with that, only the first of the 3 columns gets updated.

I tries using 3 diff commands, and this , somehow, causes col 1 and 3 to update, leaving col 2 unchanged.

THE CODE

  1. mysql_query("UPDATE client SET dod = '$dod' where ID = '$id' ");
  2.  
  3. mysql_query("UPDATE client SET mod = '$mod' where ID = '$id' ");
  4.  
  5. mysql_query("UPDATE client SET yod = '$yod' where ID = '$id' ");
Last edited by peter_budo; Jul 7th, 2008 at 7:36 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 762
Reputation: pritaeas is on a distinguished road 
Solved Threads: 124
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Master Poster

Re: updating multiple columns in single MySQL table

 
0
  #5
Jul 2nd, 2008
Are you sure all columns are of type string ? We could be of more help if you post the table structure.

Have you tried:

  1. mysql_query(...) or die(mysql_error());

to see if there is an error ?
Last edited by pritaeas; Jul 2nd, 2008 at 2:14 pm.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,071
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: updating multiple columns in single MySQL table

 
0
  #6
Jul 3rd, 2008
Hello..

Try this code to update three or more fields in database:
  1. $qur= "update `users` set `username`='".$_POST['username']."', `password`='".$_POST['password']."', `name`='".$_POST['name']."', `email`='".$_POST['emailid']."', `phone`='".$_POST['phoneno']."', `country`='".$_POST['country']."', `county`='".$_POST['county']."', `city`='".$_POST['city']."', `pincode`='".$_POST['zip']."', `shipping`='".$_POST['shipping']."', `billing`='".$_POST['billing']."', `organisation`='".$_POST['org']."', `fax`='".$_POST['fax']."' where id=".$_GET['id'];
  2. mysql_query( $qur) ;


I think it will work properly after this...

ShantI
Last edited by peter_budo; Jul 7th, 2008 at 7:37 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: updating multiple columns in single MySQL table

 
0
  #7
Jul 3rd, 2008
i have checked the table structure. All three columns i am trying to update are NOT STRINGS BUT INTEGERS (they are storing date, month and year respectively)...

The three columns are identical in every way.

When I issue the commands:

  1. mysql_query("UPDATE client SET dod = '$dod' where ID = '$id' ");
  2.  
  3. mysql_query("UPDATE client SET mod = '$mod' where ID = '$id' ");
  4.  
  5. mysql_query("UPDATE client SET yod = '$yod' where ID = '$id' ");


the 1st and the 3rd column get updated, leaving the 2nd unchanged. I know this seems funny, but i'll be really grateful if somebody could point out the error..

thx... cheers...
Last edited by peter_budo; Jul 7th, 2008 at 7:41 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,681
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 319
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: updating multiple columns in single MySQL table

 
0
  #8
Jul 3rd, 2008
if somebody could point out the error..
  1. mysql_query("update client set dod='$dod', mod='$mod',yod='$yod' where id='$id'");
seems perfectly fine. Your 3 queries are also fine. I don't see any error as there isn't any.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: updating multiple columns in single MySQL table

 
0
  #9
Jul 3rd, 2008
i tried using a common update command, but when i use it with mysql_error(), it reports the following 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 = '77' ,yod='8899' where ID =56 at line 1.


Somebody pls help...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,681
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 319
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: updating multiple columns in single MySQL table

 
0
  #10
Jul 3rd, 2008
Okay. Do this.
  1. $query = "update client set dod='$dod', mod='$mod',yod='$yod' where id='$id'";
  2. echo $query;
  3. mysql_query($query);
Tell us what it prints.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC