Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/146469-help-mysql-update-in-php-code/
Share on other sites

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]'

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

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

$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..

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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