Jump to content

Update query not executing, trying to subtract a value in the database


jdock1

Recommended Posts

Im trying to execute an update sql query, but its not working. IDK if I got the right query tho

 

what i want  to do is, when the form is submitted, subtract 15 from the value 'creditleft'. So say the value is 20 , i want to subtract 15 and get 5.

 

Here is the sql query im using;

$query2="update userdata set creditleft = - 15 where username = '".$_SESSION['login_name']."'";
						mysql_query($query2, $link);

I dont get any errors, just no output

Link to comment
Share on other sites

Haven't tested it but I think that you are just missing the brackets

 

UPDATE userdata SET creditleft = (creditleft - 15) WHERE username = $_SESSION['login_name']

 

$query2 = "UPDATE userdata SET creditleft = (creditleft - 15) WHERE username = '".$_SESSION['login_name']."'";

mysql_query($query2, $link);

 

 

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.