jdock1 Posted October 22, 2010 Share Posted October 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216592-update-query-not-executing-trying-to-subtract-a-value-in-the-database/ Share on other sites More sharing options...
jdock1 Posted October 22, 2010 Author Share Posted October 22, 2010 i also tried $query2="update userdata set creditleft = creditleft - 15 where username = '".$_SESSION['login_name']."'"; mysql_query($query2, $link); Quote Link to comment https://forums.phpfreaks.com/topic/216592-update-query-not-executing-trying-to-subtract-a-value-in-the-database/#findComment-1125312 Share on other sites More sharing options...
joesaddigh Posted October 22, 2010 Share Posted October 22, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/216592-update-query-not-executing-trying-to-subtract-a-value-in-the-database/#findComment-1125341 Share on other sites More sharing options...
BlueSkyIS Posted October 22, 2010 Share Posted October 22, 2010 the query as you have it written causes an error in MySQL, but you'll never know that unless you check. mysql_query($query2, $link) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/216592-update-query-not-executing-trying-to-subtract-a-value-in-the-database/#findComment-1125408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.