pquinn Posted March 10, 2011 Share Posted March 10, 2011 Hello, Hope I am in the right part of the forum for this 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 within a column in my SQL table: // 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%'"); 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: // 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%'"); Where 'addvaule' was the id for the value: <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> <input type="submit" name="submit" value=" Reward " /> </form> Hope I am making sense head is going to explode lol,. Any help and advice would be very much appreciated. P Quinn Quote Link to comment Share on other sites More sharing options...
Zane Posted March 10, 2011 Share Posted March 10, 2011 $_POST['addvalue'] Quote Link to comment Share on other sites More sharing options...
pquinn Posted March 10, 2011 Author Share Posted March 10, 2011 Hi, Thanks I have adjusted my code to be; <?php $add = $_POST['add']; ?> <?php $addvalue = $_POST['addvalue']?> <?php // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // 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 + '%$addvaule%') WHERE Username LIKE '%$add%'"); ?> And the action is processed but the value does not update, any advice would be great. Many thanks, P Quinn Quote Link to comment Share on other sites More sharing options...
sasa Posted March 10, 2011 Share Posted March 10, 2011 $sql = mysql_query("UPDATE UserList SET Rewards = (Rewards + $addvaule) WHERE Username LIKE '%$add%'"); Quote Link to comment Share on other sites More sharing options...
pquinn Posted March 10, 2011 Author Share Posted March 10, 2011 Hi sasa, Thank you so much it is working perfectly now I will cease smacking my head off the wall hehe Quote Link to comment Share on other sites More sharing options...
pquinn Posted March 10, 2011 Author Share Posted March 10, 2011 hmmmm The value will now update correctly but I have three columns: Rewards, Sanctions and TotalPoints The values for Rewards and Sanctions will update correctly but the Total Points will not. On page subtract_points.php the code I have updated to look like: <?php $subtract = $_POST['subtract']; $subtractvalue = $_POST['subtractvalue ']; // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // 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"); //Update Total Points query $sql = mysql_query("UPDATE UserList SET TotalPoints = (TotalPoints - $subtractvalue) WHERE Username LIKE '%$subtract%'"); ?> Basically as I reward or sanction I want the total points to reflect only the points removed so if I had picked 30 rewards and rewards the Rewards to be at 30 and TotalPoints to be at 30, but if i remove 40 I want the TotalPoints to show -10. It was working before I used the list menu that is working fine now for adding and subtracting. So close any help would be great Many Thanks, P Quinn Quote Link to comment Share on other sites More sharing options...
pquinn Posted March 10, 2011 Author Share Posted March 10, 2011 Got it was missing something, but you know i cant see the difference from whatever I just did lol Thanks again to all who helped Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.