Chevy Posted October 1, 2007 Share Posted October 1, 2007 For some reason none of my data in MySQL is updating. Is there something wrong with this code? $plusone = $info['attempts']+1; $updatea = mysql_query("UPDATE `accounts` SET `attempts`='$plusone' WHERE `username`='$username'"); $owed = (10*$info['attempts'])+20; $newpoints = $info['points']-$owed; if ($newpoints < "0"){ $newpoints = 0; } $updateb = mysql_query("UPDATE `accounts` SET `points`='$newpoints' WHERE `username`='$username'"); Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/ Share on other sites More sharing options...
shocker-z Posted October 1, 2007 Share Posted October 1, 2007 Try adding or die(mysql_error()) after running mysql_query e.g. $plusone = $info['attempts']+1; $updatea = mysql_query("UPDATE `accounts` SET `attempts`='$plusone' WHERE `username`='$username'") or die(mysql_error()); $owed = (10*$info['attempts'])+20; $newpoints = $info['points']-$owed; if ($newpoints < "0"){ $newpoints = 0; } $updateb = mysql_query("UPDATE `accounts` SET `points`='$newpoints' WHERE `username`='$username'") or die(mysql_error()); this will produce an error message stating where your error is. Regards Liam Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-358966 Share on other sites More sharing options...
Chevy Posted October 1, 2007 Author Share Posted October 1, 2007 I do not get anything when I do that :? Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359660 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 what are the datatypes of those fields your trying to update Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359680 Share on other sites More sharing options...
Chevy Posted October 1, 2007 Author Share Posted October 1, 2007 They all are numerical values, if that is what you mean. Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359697 Share on other sites More sharing options...
teng84 Posted October 2, 2007 Share Posted October 2, 2007 if you mean numeric values as int in your DB then you cant add any single ' in your set value `attempts`='$plusone' this will be invalid it should be `attempts`=$plusone to tell the Db that it is actaully a numeric value so when you put ' it will be treated as string or char that wont match your fields datatypes Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359706 Share on other sites More sharing options...
BlueSkyIS Posted October 2, 2007 Share Posted October 2, 2007 i use single quotes for EVERY database column regardless of type, at least in MySQL. single quotes around a numeric value will not affect how that value is inserted or updated, but it may prevent having malicious code inserted into your database. add: i don't think the problem is data types. i think that the data you are using to update is wrong. can you write your sql to a variable and echo that variable? Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359708 Share on other sites More sharing options...
Chevy Posted October 2, 2007 Author Share Posted October 2, 2007 Ah, okay, ill give that a try Edit: I have also tried echo-ing the data, it all is what it is supposed to be, yet it will not update. Link to comment https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.