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?

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'";
}
} 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.