Saturday, 7 September 2013

Only One Update Function Working PHP

Only One Update Function Working PHP

So I want to have a button that updates a value and changes it to "HIGH"
and another to update the same value and change it to "LOW". Both
functions work individually, but when in the same file only the one whose
input comes first works. This may sound confusing. If you look at the code
below, you can see there are two inputs. If the on function is called by
the second input, it works. If it is called by the second input function
it does not.
<?php
function off(){
mysql_connect("localhost", "root", "");
mysql_select_db("arduino");
mysql_query("UPDATE `leds` SET `state` = 'LOW' WHERE `id` = 13");
}
function on(){
mysql_connect("localhost", "root", "");
mysql_select_db("arduino");
mysql_query("UPDATE `leds` SET `state` = 'HIGH' WHERE `id` = 13");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet"
href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script
src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js">
</script>
<title></title>
</head>
<body>
<input type = "button" value = "Turn On" onclick = "<?php on(); ?>">
<br />
<br />
<input type = "button" value = "Turn Off" onclick = "<?php off(); ?>">
</body>
</html>
I am very confused by this. Anyone know what is going on. If I have not
been clear enough please say so and I would be glad to provide more
detail.

No comments:

Post a Comment