[PHP]<?php
//this function is the responsible of modifying the player in the table
function modify_table()
{
//first the query try to get a row where the name of the player is = to the name in the url
$query = "SELECT name FROM hi WHERE name='".$_GET["name"]."'";
$res = mysql_query($qu ery) or die("Couldn't execute $query: ".mysql_error() );
//if the query returns 0 rows the player doesn't exist, if it returns 1 the player already exists
if (mysql_num_rows ($res)==0)
{
//the query makes a new row with the player name and the score
$query = "INSERT INTO hi VALUES('".$_GET["name"]."',".$_GET["score"].")";
mysql_query($qu ery) or die("Couldn't execute $query: ".mysql_error() );
}
else
{
//the query looks for the row with name=name in the url and updates his score
$query = "UPDATE hi SET score=".$_GET["score"]." WHERE name='".$_GET["name"]."'";
mysql_query($qu ery) or die("Couldn't execute $query: ".mysql_error() );
}
}
?>[/PHP]
This is a snippet of my code. When i send in a request to update a player's score, it overwrites the score already there with the new value. What i want it to do is ADD to the old score (eg. old score= 100 submitted score= 50 new score =150
How would i go about this?
//this function is the responsible of modifying the player in the table
function modify_table()
{
//first the query try to get a row where the name of the player is = to the name in the url
$query = "SELECT name FROM hi WHERE name='".$_GET["name"]."'";
$res = mysql_query($qu ery) or die("Couldn't execute $query: ".mysql_error() );
//if the query returns 0 rows the player doesn't exist, if it returns 1 the player already exists
if (mysql_num_rows ($res)==0)
{
//the query makes a new row with the player name and the score
$query = "INSERT INTO hi VALUES('".$_GET["name"]."',".$_GET["score"].")";
mysql_query($qu ery) or die("Couldn't execute $query: ".mysql_error() );
}
else
{
//the query looks for the row with name=name in the url and updates his score
$query = "UPDATE hi SET score=".$_GET["score"]." WHERE name='".$_GET["name"]."'";
mysql_query($qu ery) or die("Couldn't execute $query: ".mysql_error() );
}
}
?>[/PHP]
This is a snippet of my code. When i send in a request to update a player's score, it overwrites the score already there with the new value. What i want it to do is ADD to the old score (eg. old score= 100 submitted score= 50 new score =150
How would i go about this?
Comment