Reply
Desesperate with UPDATE expression
Old 05-07-2007, 06:25 PM Desesperate with UPDATE expression
InfinitySchima's Avatar
Skilled Talker

Posts: 71
Name: Rafael Schimassek
Please help me out with this, I'm getting mad with this, am already trying to fix it for about 3 hours, just with this little expression.

Can you tell me if you find an error in this statement..
Code:
$sqlquery2 = "UPDATE mappanel SET desc='$ctrldesc', actevent1='$ctrlactevent1', actevent2='$ctrlactevent2', actevent3='$ctrlactevent3', actevent4='$ctrlactevent4', actevent5='$ctrlactevent5', actevent6='$ctrlactevent6', actevent7='$ctrlactevent7', actevent8='$ctrlactevent8', pasevent1='$ctrlpasevent1', pasevent2='$ctrlpasevent2', pasevent3='$ctrlpasevent3', paseventrate1='$ctrlpasrate1', paseventrate2='$ctrlpasrate2', paseventrate3='$ctrlpasrate3', resource1id='$ctrlresource1', resource1rate='$ctrlrsrcrate1', resource2id='$ctrlresource2', resource2rate='$ctrlrsrcrate2', resource3id='$ctrlresource3', resource3rate='$ctrlrsrcrate3' WHERE mcoord='$ctrlm' AND ycoord='$ctrly' AND xcoord='$ctrlx'";
And a output of this (with echo statement) is:
UPDATE mappanel SET desc='Update You are standing at a plain near a small portion of water.', actevent1='north', actevent2='south', actevent3='east', actevent4='west', actevent5='getrsrc1', actevent6='getrsrc2', actevent7='getrsrc3', actevent8='', pasevent1='', pasevent2='', pasevent3='', paseventrate1='', paseventrate2='', paseventrate3='', resource1id='1', resource1rate='0.8', resource2id='2', resource2rate='0.4', resource3id='3', resource3rate='0.6' WHERE mcoord='1' AND ycoord='2' AND xcoord='4'

When I run this simply nothing happens, there is no error message and the database doesn't doesn't gets updated.
I tested putting a simple "Select Expression" before and it worked; means that database is connected.
This is the first time I do an "Update" expression with more than one conditions, usually I put only one condition and it works fine.
The table name is: mappanel . The "mcoord", "ycoord" and "xcoord" are all Primary Keys and the values do exist for sure (because with a "Select" statement and a "Numrows" it displayed that there were 1 entry: SELECT * FROM mappanel WHERE mcoord='$ctrlm' AND ycoord='$ctrly' AND xcoord='$ctrlx' ). I am not updating all the values of the table, just about 21 from like ~30.

If you need more information let me know. I am really getting desesperated on this.

Schimassek-.-
InfinitySchima is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-07-2007, 06:28 PM Re: Desesperate with UPDATE expression
WebcyteDesign's Avatar
Extreme Talker

Posts: 159
Location: Hamilton
do not name a field desc as this is reserved for using with orderby.
also (this maybe be dumb but I need to point it out) numeric values should not have single quotes.

Mainly I believe you should change desc to maybe fldDesc
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Old 05-07-2007, 07:17 PM Re: Desesperate with UPDATE expression
Learning Newbie's Avatar
Moderator

Posts: 4,879
Name: John Alexander
Also if you can use a stored procedure instead of building the UPDATE statement on the fly, you'll have more control, it'll run faster, but the best reason of all is it will MUCH easier to debug in situations like this.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is online now
Reply With Quote
View Public Profile
 
Old 05-08-2007, 10:35 AM Re: Desesperate with UPDATE expression
Average Talker

Posts: 29
Name: Amit Soni
It appears that the mysql Username with which you are logging into mysql does not have permissions to write to the table. What happens if you put
Code:
echo mysql_errno() . ": " . mysql_error() . "\n";
right after running the mysql_query() function ?
--Amit
Zitku is offline
Reply With Quote
View Public Profile Visit Zitku's homepage!
 
Old 05-08-2007, 03:51 PM Re: Desesperate with UPDATE expression
InfinitySchima's Avatar
Skilled Talker

Posts: 71
Name: Rafael Schimassek
Quote:
also (this maybe be dumb but I need to point it out) numeric values should not have single quotes.
Strange, I have always put it with single quotes and it worked fine, but I will try putting it without and change the "desc" column.


Quote:
Also if you can use a stored procedure instead of building the UPDATE statement on the fly, you'll have more control, it'll run faster, but the best reason of all is it will MUCH easier to debug in situations like this.
What is that? It's just one UPDATE statement in a loop...


Quote:
What happens if you put...
Permission I have for sure, because there are other parts of the program who update a value in there (but they are only single updates with multiple conditions). I have put the code you gave me and it displayed the following:
1064: 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 'desc='YUpdateou are standing at a plain near a small portion of water.', acteven' at line 1
This is nice to see, unfortunately I don't know what I have put wrong, but I will try to change the "desc" to "description" and then add the result to my post.

Schimassek...

EDIT: IT WORKED! Thanks a lot WebcyteDesign, it really was because of this "desc", Learning Newbie, could you explain me about that stored procedure, and thanks Zitku for giving me the code to see the errors, this might come in handy later.

Last edited by InfinitySchima : 05-08-2007 at 04:00 PM. Reason: Solved
InfinitySchima is offline
Reply With Quote
View Public Profile
 
Old 05-08-2007, 08:04 PM Re: Desesperate with UPDATE expression
Learning Newbie's Avatar
Moderator

Posts: 4,879
Name: John Alexander
Quote:
Originally Posted by InfinitySchima View Post
EDIT: IT WORKED! Thanks a lot WebcyteDesign, it really was because of this "desc", Learning Newbie, could you explain me about that stored procedure, and thanks Zitku for giving me the code to see the errors, this might come in handy later.
A stored procedure is a compiled SQL statement ( or many of them ) inside the database. You send it parameters, and it interacts with your base tables. It's faster, more secure, uses less network bandwidth, and easier to debug / less prone to error. Highly recommended.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is online now
Reply With Quote
View Public Profile
 
Old 05-09-2007, 02:58 AM Re: Desesperate with UPDATE expression
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,024
Name: Forrest Croce
Location: Seattle, WA
For the record, Stored Procedures are only available in MySQL 5+ so it really depends how your server is set up whether it's even possible to take advantage of them. But if you can, they're very useful.

It was the desc column breaking your query; that's a reserved word for descending sorts ( ... order by id desc ). Maybe this is what John meant about debugging, but if you used a proc, it would tell you ahead of time that the query was invalid. ( I think you could override the default by putting the column name in quotes, though? )

You would create and use one like this:

[code]
Create Procedure updMapPanel
@arg1 varChar(100),
@arg2 varChar(100)
As
UPDATE mappanel SET actevent1 = @arg1 Where xCoord = @arg2
[/CODE\]

And then you would use it like this:

Code:
   EXECUTE
Code:
updMapPanel 'someValue', 'anotherValue'


I could be a little off on how MySQL handles args and whatnot; I use SQL Server. Oracle uses : in place of @ and MySQL might have a different character. In any case, the second query (
EXECUTE updMapPanel ) takes the place of the update command in your code. In SQL Server this has memory and CPU benefits, which might or might not be the case in other database engines.

Anyway, I hope that clears up the confusion.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 05-09-2007, 07:08 AM Re: Desesperate with UPDATE expression
InfinitySchima's Avatar
Skilled Talker

Posts: 71
Name: Rafael Schimassek
I understand better now, I will search on the internet for this.

So basically they are some commands I store in the database and assign them an ID?

But just one more question. To create those stored procedures, I do it at my PHP file or write them down in the Database Server (I use MySQL)?

Schimassek...
InfinitySchima is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Desesperate with UPDATE expression
 

Thread Tools

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 Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15506 seconds with 13 queries