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? 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'"; } } ?> 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
Archived
This topic is now archived and is closed to further replies.