Jump to content

upudating database


droidus

Recommended Posts

Hello.

 

How would I write this code?:

 

mysql_query(sprintf("UPDATE members(notes) SET VALUES('%s') WHERE uname = $_SESSION[user]",mysql_real_escape_string($notes)))

 

I want to update the notes column in my database to the variable, $notes.

 

thanks.

Link to comment
Share on other sites

having the sprintf in there kinda throws me off.  otherwise, i would understand how to do it. :P

 

With sprintf the %s you embed gets replaced with the value of the parameter you provide, while also being conformed to the formatting specified.  '%s' just specifies that it needs to be a string, so I don't see a lot of value to using it here over using concatenation. 

 

Done what Zanus suggests is not a bad idea, because you can var_dump($q) and see if it's a valid sql statement if you want, however your main mistake as he also pointed out is that with updates there is no VALUES keyword.  You do

 

SET columname = the_value

 

And if you have multiple columns to update

 

SET columnname1 = a value, columname2 = another value, etc...

 

If your syntax had been correct it would have worked even doing it the original way you had it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.