godsent Posted January 10, 2010 Share Posted January 10, 2010 If this is a good way to see if action was successful to continue: function changeGameState($GameId) { mysql_query("UPDATE challenges SET status=status+1 WHERE id='$GameId'"); } if (changeGameState($someId)) { //was successful } I dont know if it work or not, but i think no because changeGameState wont return any value, so I came up with another idea, but it gives me "Parse error: syntax error, unexpected T_RETURN " error in "return 0" line public function changeGameState($GameId) { mysql_query("UPDATE challenges SET status=status+1 WHERE id='$GameId'")or die(return false); return true; } how can i check if action was succesful before continuing? Quote Link to comment https://forums.phpfreaks.com/topic/187930-true-way-to-see-if-action-was-successful/ Share on other sites More sharing options...
sasa Posted January 10, 2010 Share Posted January 10, 2010 try function changeGameState($GameId) { $res = mysql_query("UPDATE challenges SET status=status+1 WHERE id='$GameId'"); return mysql_affected_rows($res); } if (changeGameState($someId)) { //was successful } Quote Link to comment https://forums.phpfreaks.com/topic/187930-true-way-to-see-if-action-was-successful/#findComment-992255 Share on other sites More sharing options...
godsent Posted January 10, 2010 Author Share Posted January 10, 2010 try function changeGameState($GameId) { $res = mysql_query("UPDATE challenges SET status=status+1 WHERE id='$GameId'"); return mysql_affected_rows($res); } if (changeGameState($someId)) { //was successful } Works fine thanks, success returns 1, fail = -1. Quote Link to comment https://forums.phpfreaks.com/topic/187930-true-way-to-see-if-action-was-successful/#findComment-992259 Share on other sites More sharing options...
ignace Posted January 10, 2010 Share Posted January 10, 2010 That's not good because then the action was always successfull. if (0 < changeGameState($someId)) Quote Link to comment https://forums.phpfreaks.com/topic/187930-true-way-to-see-if-action-was-successful/#findComment-992269 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.