xwishmasterx Posted May 20, 2012 Share Posted May 20, 2012 Hello I am trying to do a simple button that will change a single field in database depending on its already existing value eg: if value is 0 then button should read 0 and on click change value in field to 1, and then button should read 1. Basically an "ON/OFF" button. Any examples to do this in a simple way? Quote Link to comment https://forums.phpfreaks.com/topic/262835-most-simple-button-possible-to-update-db/ Share on other sites More sharing options...
NLT Posted May 20, 2012 Share Posted May 20, 2012 This should work: <form method="post"> <input type="submit" value="Change" name="ssubmit" /> </form> <?PHP if(isset($_POST['ssubmit'])) { $sql = "SELECT * FROM `table` WHERE `something`='0'"; $result = mysql_num_rows(mysql_query($sql)); if($result == 1) { $query = mysql_query("UPDATE `table` SET `something`='1'"); echo "Value changed to '1'"; } else { $query = mysql_query("UPDATE `table` SET `something`='0'"); echo "Value changed to '0'"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262835-most-simple-button-possible-to-update-db/#findComment-1347090 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.