Page 1 of 1
How to update/add number?
Posted: Fri Mar 23, 2007 5:51 am
by jmansa
I have a database with 8 players ranking. (id, name, point) I the have a form where can insert points for each player whenever a match is done. Now i want to send the new data to the db and the add the new points to the points the allready have... e.g. if player 1 (id=1, name=john, point=11) should have earned 4 points, then when i submit my form his data should look like this (id=1, name=john, point=15).
I know how to insert data, and update but how do I add this together?
All respect...
Posted: Fri Mar 23, 2007 6:01 am
by crazytopu
get the existing value i.e 11, add 4 and save back the new value.
Posted: Fri Mar 23, 2007 6:06 am
by JayBird
Code: Select all
UPDATE `players` SET `points` = `points` + $points WHERE `id` = $userID
Posted: Fri Mar 23, 2007 10:20 am
by jmansa
Looks like the right direction, but... I have tryid this but with error...
My form:
Code: Select all
<form id="form1" name="form1" method="post" action="index.php?page=oom_aprove">
<input name="arneid" type="hidden" id="arneid" value="1">
<input name="arnepla" type="text" size="5" class="form1"/>
<input name="arnepoint" type="text" size="5" value="0" class="form1"/>
<input name="boid" type="hidden" id="boid" value="2">
<input name="bopla" type="text" size="5" class="form1"/>
<input name="bopoint" type="text" size="5" value="0" class="form1"/>
<input type="submit" name="Submit" value="Submit">
Aprove script:
Code: Select all
$apuserid=$_POST['arneid'];
$bcuserid=$_POST['boid'];
$appoints=$_POST['arnepoint'];
$bcpoints=$_POST['bopoint'];
$query="UPDATE cms_orderofmerit_2007 SET Point = Point + $appoints WHERE ID = $apuserid";
mysql_query($query);
$query="UPDATE cms_orderofmerit_2007 SET Point = Point + $bcpoints WHERE ID = $bouserid";
mysql_query($query);
if(!mysql_query($query)){
print "Error Occurred:". mysql_error() ;
exit();
}
echo "Table updatet...";
mysql_close();
My error:
Error Occurred:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Can somebody see where I go wrong!?
Posted: Fri Mar 23, 2007 10:30 am
by JayBird
Change this
Code: Select all
print "Error Occurred:". mysql_error() ;
to this
Code: Select all
print "Error Occurred:". mysql_error() ;
echo $query;
Then post what it returns
Posted: Fri Mar 23, 2007 10:47 am
by jmansa
This is what it returns...
Error Occurred:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
UPDATE cms_orderofmerit_2007 SET Point = Point + 5 WHERE ID =
It seems like it doesnt get the ID??? Why?
Posted: Fri Mar 23, 2007 10:49 am
by JayBird
where do you set $apuserid??
Posted: Fri Mar 23, 2007 11:03 am
by jmansa
In my form I have a hidden field like this:
Code: Select all
<input name="arneid" type="hidden" id="arneid" value="1">
Then in my aprove script i get it like this:
But actually it would be alot easier if I just inserted the ID number in forehand like this, but I the get an error?
Code: Select all
$query="UPDATE cms_orderofmerit_2007 SET Point = Point + $appoints WHERE ID = 1";
mysql_query($query);
How do I just staticly set the ID?