General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 22nd, 2003, 08:18 AM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What's wrong with these UPDATE statements?

Hi,
I am having trouble updating a record in MySQL.
Below are several different methods I have tried to use. The problem seems to be in the WHERE part, for when the query appears on multiple lines, the error message points to the line with the WHERE statement.
Here are some of the ways I have tried:

PHP Code:
 $dbQuery "UPDATE tbluser SET usrTplID=$_SESSION[tplid], usrTplName='$_SESSION[tplname]' ";
$dbQuery .= "WHERE usrUsername='$_SESSION['user']';";
mysql_query($dbQuery); 


PHP Code:
 mysql_query("UPDATE tbluser SET usrTplID='$_SESSION[tplid]' WHERE usrUsername='$_SESSION['user']' AND usrPassword='$_SESSION['pass']' AND usrSiteName='$_SESSION['site']'") OR die; 


PHP Code:
 mysql_query("UPDATE tbluser SET usrTplID=$_POST['rbtTemplate'] WHERE usrUsername=$_SESSION['user'] AND usrPassword=$_SESSION['pass'] AND usrSiteName=$_SESSION['site']"); 


PHP Code:
 mysql_query("UPDATE tbluser SET usrTplName='$_SESSION[tplname]', usrTplID='$_SESSION[tplid]' WHERE usrUsername='$_SESSION['user']' AND usrPassword='$_SESSION['pass']' AND usrSiteName='$_SESSION['site']'"); 


PHP Code:
 mysql_query("UPDATE tbluser SET usrTplName='$_POST['hfTplName']', usrTplID='$_POST['rbtTemplate']' WHERE usrUsername='$_SESSION['user']' AND usrPassword='$_SESSION['pass']' AND usrSiteName='$_SESSION['site']'"); 


The error message I receive is:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in step1update.php on line 19
(line 19 in this case is
$dbQuery .= "WHERE usrUsername='$_SESSION['user']';"

So, I have tried updating only one field, or putting only one condition in the WHERE statement, but it makes no difference...
The error message of of no help either: when I look it up in the PHP manual there's no reference for any of them; just the T_VARIABLE has a reference but is of no help.
I'm stuck... Anyone has any ideas?

Thanks for your help,

Toine

Reply With Quote
  #2  
Old November 22nd, 2003, 11:52 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
The problem is that you're trying to nest quotes. Try reformatting your query lines according to the following example:

PHP Code:
 mysql_query("UPDATE tbluser SET usrTplName='" $_POST['hfTplName'] . "', usrTplID='" $_POST['rbtTemplate'] . "' WHERE usrUsername='" $_SESSION['user'] . "' AND usrPassword='" $_SESSION['pass'] . "' AND usrSiteName='" $_SESSION['site'] . "'"); 


(I don't know why the forum is insisting on sticking line breaks in the code. I've deleted them.)

Reply With Quote
  #3  
Old November 22nd, 2003, 08:09 PM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks, that method worked!

Thank you for your help,

Toine

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > What's wrong with these UPDATE statements?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway