Jump to content

** MySQL UPDATE and WHERE clause help! **


Recommended Posts

Hey guys! I am new to the forums and am looking for some help. First off I am using 000webhost.com as a host and it is running PHP 5.2. and MySQL 5.0.81-community.

 

I am fairly new to PHP and completely new to MySQL. I am self taught and normally can figure things out myself but I am really puzzled on this one.

 

I am in the process of creating a text based game. The problem comes when I have the user go to "the mines" and "mine" for gold. Right now I have it set so every time they mine they get 100 gold. I want the users gold to go up by 100 obviously and I want it reflected in both my database and the members profile.

 

I assume to do this I would use the MySQL UPDATE function. This is what I have been doing but I cant seem to figure out how to get only that users gold to go up. I did some research and found out about the WHERE clause and have tried to use it to identify the user but I cant seem to work it out.

 

This is what I have so far:

 

I connect to the the MySQL server, and select the database then I wrote this line of code:

 

$temp_gold = $_SESSION['MEMBER_GOLD'] + 100;


$result = mysql_query("UPDATE members SET gold= $temp_gold WHERE member_id = ’{$_SESSION['MEMBER_ID']}'");

 

$_SESSION['MEMBER_GOLD'] is the members gold when the user first logged in and $_SESSION['MEMBER_ID'] is the users ID.

 

To me the statement makes perfect sense. Update the table "members" and set "gold" equal to "$temp_gold" which is the gold before + 100. Obviously this is wrong though and I would really appreciate your guys help! Thanks in advance.

 

 

Link to comment
https://forums.phpfreaks.com/topic/191444-mysql-update-and-where-clause-help/
Share on other sites

Hey guys thanks for your help. The problem ended up being that strange ' char. I think I copied and pasted that code from somewhere so I didn't write it myself.

 

Sorry about now being so descriptive. I'm sure I'll have more questions to ask in the upcoming days. Thanks!

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.