gesseg Posted June 14, 2010 Share Posted June 14, 2010 Hi, Im trying (and failing) to add results from a form to existing results in the table. So if the row "skill" was 10 then the form submitted had a skill value of 5 the table would update to 15. Im sure there is an easy way of doing this but Ive searched the web and canfind one. Heres my code: <?php $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT skill FROM database WHERE name = '$_POST[name]'"); mysql_query("UPDATE database SET skill = '$_POST[skill] + $result' WHERE name = '$_POST[name]'"); mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted June 14, 2010 Share Posted June 14, 2010 There is. mysql_query("UPDATE database SET skill = (skill + {$_POST['skill']}) WHERE name='{$_POST['name']}'"); That should do the trick. Quote Link to comment Share on other sites More sharing options...
gesseg Posted June 14, 2010 Author Share Posted June 14, 2010 Thanks very much I knew there would be an easy way to do it. 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.