943,598 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 20519
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jul 4th, 2008
0

Re: updating multiple columns in single MySQL table

it prints the query (since i have given: "echo $query").

but the update does not occur....

this is really confusing... wats the problem???
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 4th, 2008
0

Re: updating multiple columns in single MySQL table

What exactly does it print ?
Last edited by nav33n; Jul 4th, 2008 at 10:04 am.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 5th, 2008
0

Re: updating multiple columns in single MySQL table

i entered the date as 10/4/2008...

it shows:-

update client set dod='10', mod='4',yod='2008' where id='120'....

and then the table (with the 'date' and 'year' column updated, but the 'month' column as it is...)..

pls suggest...

thx...
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 5th, 2008
0

Re: updating multiple columns in single MySQL table

I think the update commands with three column update should work fine. But you can check what are the values you are supplying, what are the table column data type, check are you sending null values or not, you may need to convert data to the right type.

Try to print the query with
echo $query_string_variable

Then execute the query in the database by itself [not from PHP [I mean in mysql console/GUI/Mysql Browser/PhpMyAdmin].
] and see if it runs or what kind of errors it provides


You can also try the other way....try to write a query by providing static values and run the query into the database. if the query runs take it and use variables to provide the values. See what it does. Also, print these query and execute in the backend database [I mean in mysql console/GUI/Mysql Browser/PhpMyAdmin].
Reputation Points: 10
Solved Threads: 3
Newbie Poster
sayedjustetc is offline Offline
19 posts
since Jun 2008
Jul 6th, 2008
0

Re: updating multiple columns in single MySQL table

Strange! Now, execute this query in mysql console or phpmyadmin. If it still doesn't update, check the column datatype. I don't see any problem with the query.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 7th, 2008
0

Re: updating multiple columns in single MySQL table

Quote ...

I think the update commands with three column update should work fine. But you can check what are the values you are supplying, what are the table column data type, check are you sending null values or not, you may need to convert data to the right type.

Try to print the query with
echo $query_string_variable

Then execute the query in the database by itself [not from PHP [I mean in mysql console/GUI/Mysql Browser/PhpMyAdmin].
] and see if it runs or what kind of errors it provides


You can also try the other way....try to write a query by providing static values and run the query into the database. if the query runs take it and use variables to provide the values. See what it does. Also, print these query and execute in the backend database [I mean in mysql console/GUI/Mysql Browser/PhpMyAdmin].

Click to Expand / Collapse  Quote originally posted by nav33n ...
Strange! Now, execute this query in mysql console or phpmyadmin. If it still doesn't update, check the column datatype. I don't see any problem with the query.


Well, i tried running the query using the MySQL GUI (NaviCAT) wioth static data. Again, the same problem arises. The query runs perfectly well for 'dod' and 'yod', but when i run it for 'mod', it shows the error,

You have an error in your SQL syntax, check the manuala that corresponds to your MySQL server version for the right syntax to use near 'mod = '12' where ID = '1" at line 1

PS... The query i used was :=- UPDATE client SET mod = '12' where ID = '1'

with exactly the shown usage of (' '), but the error shows a certain different type of usage.


PS2-- I have also tried using 'text' for the defintion of the 3 columns in the table, and hav even tried int(the 3 cols are basically for date, month and year)... but both produce the same results.

somebody pls suggest sumthing... this is getting really fustrating...


thx nav33 and sayedjustetc for your time n effort.
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 7th, 2008
0

Re: updating multiple columns in single MySQL table

Why are you using single quotes around the variables in your queries? If the fields are integers, they don't require string indicators. I thought their presence would cause the query to fail by themselves (not in MySQL, I guess). Is the ID field also an integer?

Oh, and isn't "mod" a PHP or MySQL reserved word? That could very well be the other part of your problem.

Try renaming the mod field to modnum (or something similar) and executing:
"update client set dod=$dod, modnum=$mod, yod=$yod where id=$id";
Last edited by badbart; Jul 7th, 2008 at 1:15 pm.
Reputation Points: 30
Solved Threads: 1
Newbie Poster
badbart is offline Offline
12 posts
since Sep 2007
Jul 7th, 2008
0

Re: updating multiple columns in single MySQL table

Quote ...
Oh, and isn't "mod" a PHP or MySQL reserved word? That could very well be the other part of your problem.
Ah! Exactly. You nailed it. This will do.
mysql Syntax (Toggle Plain Text)
  1. UPDATE client SET dod='10', `MOD`='4',yod='2008' WHERE id='120'
Notice the extra ` around mod. It will make a keyword to be used 'without any error'. But, its not a good thing to have keywords as columnnames.
Cheers,
Naveen

Edit: mod is a mysql reserve word.
Last edited by nav33n; Jul 7th, 2008 at 1:41 pm.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 7th, 2008
0

Re: updating multiple columns in single MySQL table

Click to Expand / Collapse  Quote originally posted by badbart ...

Oh, and isn't "mod" a PHP or MySQL reserved word? That could very well be the other part of your problem.
Well badbart, as nav33n said, you hit the nail on the head. I just changed the name of the field and the system worked...thx a ton for the suggestion coz such things are exttreemely difficult to identify....


a big thx also to nav33n and to sayedjustetc for their time and effort.... thnk u guys... thx a lot...
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Oct 25th, 2008
0

Re: updating multiple columns in single MySQL table

i dont understand u r problem but i know is

$_post['dd'] = $dd;
$_post['mm'] = $mm;
$_post['yy] = $yy;
$dob="$dd/$mm/$yy";
mysql_query("update set users where dateofbirth = '$dob' ");


or
update set users where username=$u,password=$p ... like that also
Reputation Points: 10
Solved Threads: 0
Newbie Poster
suredurga is offline Offline
3 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help!!!! open source SMS Shopping Project
Next Thread in PHP Forum Timeline: update data through dropdown





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC