nauir Posted February 23, 2009 Share Posted February 23, 2009 I am an amateur. I have taught myself everything. I want to know why this isn't working... Maybe I haven't learned the new technique for doing it but it should work I think. It won't add/subtract the money to either player's account. mysql_query(" UPDATE player SET Money - '$bid[amount]' WHERE id = '$bid[bidderid]' ")or die(mysql_error()); mysql_query(" UPDATE player SET Money + '$bid[amount]' WHERE id = '$bid[bidderid]' ")or die(mysql_error()); I appreciate all your future help! P.S. I made this completely odd looking when I was trying to fix it. All of the variables work.. but for some reason it won't update. Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/ Share on other sites More sharing options...
JoeBuntu Posted February 23, 2009 Share Posted February 23, 2009 syntax is bad: your statement should be in this format: UPDATE someTable SET someColumn=value1, otherColumn=value2 where someField = condition so you'll have to rearrange your terms a little bit Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-768938 Share on other sites More sharing options...
nauir Posted February 23, 2009 Author Share Posted February 23, 2009 I am trying to add and subtract something though.. Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-768949 Share on other sites More sharing options...
Zane Posted February 23, 2009 Share Posted February 23, 2009 first of all....wrong forum...(I'll move it) second of all...your Money field has to be a numeric data type and third...you need to change your query just a bit this SET Money - '$bid[amount]' should be SET Money = Money - '$bid[amount]' Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-768951 Share on other sites More sharing options...
nauir Posted February 23, 2009 Author Share Posted February 23, 2009 I tried that before but I'll try it again. Thanks for moving it. Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-768957 Share on other sites More sharing options...
Zane Posted February 23, 2009 Share Posted February 23, 2009 also you might want to take the number out of quotes...since it is in fact a number and not a string SET Money = Money - $bid[amount] and your associative index syntax is bad too...should be $bid['amount'] so in conclusion UPDATE player SET Money = Money - {$bid['amount']} WHERE id = {$bid['bidderid']} UPDATE player SET Money = Money + {$bid['amount']} WHERE id = {$bid['bidderid']} and the curly braces are there to avoid excess concatenation Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-769015 Share on other sites More sharing options...
fenway Posted February 23, 2009 Share Posted February 23, 2009 Hope you're using transactions... Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-769059 Share on other sites More sharing options...
nauir Posted February 23, 2009 Author Share Posted February 23, 2009 Man.. I tired that and it still won't work. I don't get an error it just doesn't update it. The host on this site is Bluehost.com.. Maybe it is their server? Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-769421 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2009 Share Posted February 23, 2009 Either your code is not being executed for some reason, such as being in conditional logic that is FALSE (you would need to post all the relevant code for anyone to be able to help) or whatever is in $bid['bidderid'] does not match anything in your table (you would need to echo the query to see what is in it.) Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-769428 Share on other sites More sharing options...
nauir Posted February 23, 2009 Author Share Posted February 23, 2009 $bid['bidderid'] is from a column in a table in a database. It is calling the bidder's id that is stored in the table. I made it so that it prints out this info: Congratz, you accepted bidder id: (id here)'s bid of (amount) on item (item number). And it all shows up like it is working. I'm lost.. Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-769444 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2009 Share Posted February 23, 2009 If WHERE id = {$bid['bidderid']} (or whatever you have for the current code) does not match EXACTLY, the UPDATE won't execute. Just because you can echo something and it appears to be correct, does not mean it is the same. Use var_dump if you have to in order to make sure that the variable contains exactly what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-769449 Share on other sites More sharing options...
fenway Posted February 24, 2009 Share Posted February 24, 2009 Stop all of this hand-waving -- echo the ACTUAL mysql query string that's sent to the server, then we'll talk. Quote Link to comment https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/#findComment-770171 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.