Using UPDATE and SET to add or subtract a value
Posted: Thu Mar 10, 2011 4:48 am
Hello,
First time posting here so it is nice to meet you all.
I have been teaching my self php for a few weeks now and I have hit a brick wall
Using the following code I have been able to add or subtract values in a column within my SQL table:
But for the life me I can not figure out how to use a List/Menu with values of 10, 20, 30 & 40 to be the amount added rather than having a default amount in the query.
I tried:
Where 'addvaule' was:
But it does not add the value 
Any help anyone can provide would be really appreciated.
Many Thanks
PQ
First time posting here so it is nice to meet you all.
I have been teaching my self php for a few weeks now and I have hit a brick wall
Using the following code I have been able to add or subtract values in a column within my SQL table:
Code: Select all
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot SELECT DB");
//Add query
$sql = mysql_query("UPDATE UserList SET Rewards = (Rewards + 10) WHERE Username LIKE '%$add%'");I tried:
Code: Select all
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot SELECT DB");
//Add query
$sql = mysql_query("UPDATE UserList SET Rewards = (Rewards + '%$addvalue%') WHERE Username LIKE '%$add%'");Code: Select all
<form action="add_points.php" method="post" class="style13">
<input name="add" type="text" id="add" />
</label><label>
<select name="addvalue" id="addvalue">
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
</form>Any help anyone can provide would be really appreciated.
Many Thanks
PQ