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); ?> Link to comment https://forums.phpfreaks.com/topic/204706-adding-results-to-field/ 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. Link to comment https://forums.phpfreaks.com/topic/204706-adding-results-to-field/#findComment-1071700 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. Link to comment https://forums.phpfreaks.com/topic/204706-adding-results-to-field/#findComment-1071702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.