#1 (permalink)  
Old 05-12-2005, 07:31 PM
Registered User
 
Join Date: Apr 2005
Posts: 7
php variables in the Set clause of mysql UPDATE

hey,
So youve got your typical UPDATE statement, UPDATE Table SET column = 'data'. What im wondering is if its possible to have the column aspect of that to be a php variable? I've been trying this but nothing seems to happen, and I dont get any error, so I think the code just recognizes it as a string, not as the value of the variable. I tried to echo the variable to see if that would work, but then I got a parse error. Anyone have any other ideas? any help would be greatly appreciated, thanks!!
Reply With Quote

  #2 (permalink)  
Old 05-12-2005, 08:13 PM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
Quote:
Originally Posted by theninjasquad
hey,
So youve got your typical UPDATE statement, UPDATE Table SET column = 'data'. What im wondering is if its possible to have the column aspect of that to be a php variable? I've been trying this but nothing seems to happen, and I dont get any error, so I think the code just recognizes it as a string, not as the value of the variable. I tried to echo the variable to see if that would work, but then I got a parse error. Anyone have any other ideas? any help would be greatly appreciated, thanks!!
Share your code snippet so people see what you are doing.
Reply With Quote
  #3 (permalink)  
Old 05-12-2005, 08:31 PM
Registered User
 
Join Date: Apr 2005
Posts: 7
okay heres the code:

mysql_query("UPDATE PL0105 SET $column = '$key' WHERE IDString = '$ID'", $db) or die(mysql_error());

I tried changing the $column to be <?php echo $column ?> instead, but I get a parse error still. I think it might be because my main code is in php brackets already, and I'm trying to add php brackets into that. But i dont see any other way around it... any ideas?
Reply With Quote
  #4 (permalink)  
Old 05-12-2005, 08:39 PM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
Try this:

Code:
$query = sprintf(
  "UPDATE PL0105 SET %s = '%s' WHERE IDString = '%s'",
  $column,
  $key,
  $ID
  );
echo "Query: $query";
mysql_query($query, $db) or die(mysql_error());
Reply With Quote
  #5 (permalink)  
Old 05-12-2005, 10:02 PM
Registered User
 
Join Date: Apr 2005
Posts: 7
omg thank you sooooo so much!!!!!!
Reply With Quote
Reply


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 06:00 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter