Jump to content

most simple button possible to update DB?


xwishmasterx

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.