473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UPDATE won't; value is unchanged in MySQL table

ok here goes, this is killing me.

this is my attack script.

Expand|Select|Wrap|Line Numbers
  1. function attack(){
  2.     global $targetname;
  3.     $healthbefore = getValueID("health", "userdata", $_SESSION['id']);
  4.     $dmgrand= mt_rand(1,10);
  5.     $strength = 10;
  6.     $dmg = ($dmgrand * $strength);
  7.     $healthafter = ($healthbefore - $dmg);
  8.     if ($healthafter < 0){
  9.         $healthafter = 0;
  10.     }
  11.     updateValueUSER("health", "$healthafter", "userdata", "$targetname");
  12.  
  13.     echo "Health before was $healthbefore. You dealt $dmg damage. $targetname now has $healthafter health left.";
  14. }
here's updateValueUSER:

Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3.     $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4.     $result = mysql_query($q,$conn);
  5. }
the problem is that it never sets the value of "health" in the database to $healthafter. every time I try to check the health, it's back at 100. anyone have an idea? this is really killing me...
Aug 21 '07 #1
10 1855
ak1dnar
1,584 Expert 1GB
akapsycho,

A Thread Title Like; about to pull my hair out, mysql & php question
Not Strong enough to describe your question.

You may better to Go through FAQ
Thanks for your time.
Aug 21 '07 #2
ak1dnar
1,584 Expert 1GB
Shall we print the Called Parameters First.

Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3. //$q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4. //$result = mysql_query($q,$conn);
  5. echo $column. $value. $table.$username;
  6. }
Aug 21 '07 #3
pbmods
5,821 Expert 4TB
Alternatively (sorry Ajaxrand):
Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3.     $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4.     $result = mysql_query($q,$conn);
  5.  
  6.     echo $q, '<br /><br />', mysql_error();
  7. }
  8.  
Aug 21 '07 #4
ak1dnar
1,584 Expert 1GB
Alternatively (sorry Ajaxrand):
Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3.     $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4.     $result = mysql_query($q,$conn);
  5.  
  6.     echo $q, '<br /><br />', mysql_error();
  7. }
  8.  
Oh Yes that's cool, then you have the chance to find out what's going on with the Connection,Query String.
Aug 21 '07 #5
Sorry about the title, I was going crazy and I put it up there in desperation. I've already tried echoing all the parameters and they are all exactly what they should be. I'll try

echo $q, '<br /><br />', mysql_error();

and see what that does. What is it supposed to do? Thanks for your help.
Aug 21 '07 #6
Alright well it first gave me:
Expand|Select|Wrap|Line Numbers
  1. "UPDATE userdata SET health = 80 WHERE username = 'reallylongnamehi'"
and then it told me that username was invalid, which it was, so i set that to user.

now it gives me:
Expand|Select|Wrap|Line Numbers
  1. "UPDATE userdata SET health = 40 WHERE user = 'reallylongnamehi'"
without an error. Still doesn't update the entry even though it seems that everything should be working...
Aug 21 '07 #7
Another thing i've noticed is that when I add another function I made to retrieve data,
Expand|Select|Wrap|Line Numbers
  1. echo getValueUSER("health", "userdata", "$targetname");
it gives me the correct value for health after the attack. that means it must be getting reset somewhere...
Aug 21 '07 #8
ARGH got it...I was using $_SESSION['id'] instead of the target's id...man I feel dumb right now...thanks for all of your help
Aug 21 '07 #9
pbmods
5,821 Expert 4TB
Heya, akapsycho.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 21 '07 #10
Thanks a lot pbmods. I've been pleasantly surprised by how constructive this forum is and I'll be sure to look around if I can find anyone who I can help. Thanks for everyone's help again!
Aug 21 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
5
by: rdraider | last post by:
Hi all, I'm looking for a way to re-number inventory items. The items exist in 50+ tables, hundreds of fields and there are several thousand items. Maybe one table could hold the list of old &...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
11
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.