How to update/add number?
Moderator: General Moderators
How to update/add number?
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...
I know how to insert data, and update but how do I add this together?
All respect...
Code: Select all
UPDATE `players` SET `points` = `points` + $points WHERE `id` = $userIDLooks like the right direction, but... I have tryid this but with error...
My form:
Aprove script:
My 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">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();Can somebody see where I go wrong!?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
Change this
to this
Then post what it returns
Code: Select all
print "Error Occurred:". mysql_error() ;Code: Select all
print "Error Occurred:". mysql_error() ;
echo $query;In my form I have a hidden field like this:
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?
How do I just staticly set the ID?
Code: Select all
<input name="arneid" type="hidden" id="arneid" value="1">Code: Select all
$apuserid=$_POST['arneid'];Code: Select all
$query="UPDATE cms_orderofmerit_2007 SET Point = Point + $appoints WHERE ID = 1";
mysql_query($query);