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

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);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.