+----------------+-----------+
|name(varchar)PK |money(int) |
+----------------+-----------+
How can i formulate a query so that it can:
1.Be able to insert a name and money value
2.If the said name already exists it should only update the money column by adding its value with that it gets from a form. tried using:
REPLACE INTO practable SET name = '$name', money = 'money' + $amount
It fulfills the first requirement but while updating the money column it simply replaces the old value with the new one, doesn't add them.
Here is the full code(Draft version):
<?php
//This script by another form which takes the amount and name paramters from user
if(!empty($_GET['nameg']) && !empty($_GET['amountg'])){
$user="root";
$pass="password";
$db="practice";
$name=$_GET['nameg'];
$amount=$_GET['amountg'];
mysql_connect('localhost',$user,$pass) or die("Connection Failed!, " . mysql_error());
$query="REPLACE INTO practable SET name = '$name', given = 'given' + $amount";
mysql_select_db($db) or die("Couldn't connect to Database, " . mysql_error());
mysql_query($query) or die("Couldn't execute query! ". mysql_error());
mysql_close() or die("Couldn't disconnect!");
}
?>