I am building a website interface to control a Arduino through a webserver on my Raspberry for a university project. I am using php, python and a mySQL database to set and store the "status" of the equipment. I don't have much experience in php or python but im making dew. My problem however is using a checkbox to switch these devices on or off. I created a connection to the database in php. I have researched alot of giberish that doesn't seem to relate to my project. Here is my test.php code:
The PHP:
//$alarm = $_GET["alarm"];
> $sql = mysql_query("UPDATE elements SET value=" .
mysql_real_escape_string($_GET["alarm"])
. " WHERE element='alarm'");
> if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else { echo "Error updating record: " . $conn->error;
}
> $sql = "SELECT value FROM elements WHERE element='Alarm'";
> result = $conn->query($sql);
> if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Value: " . $row["value"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
The HTML:
`<form id="alarm" action="test.php" method="get">`
`<input type="checkbox" name="alarm" value="1">Alarm`
`</form>`
Please if you can just point me on the right direction. I appreciate any feedback in advance.
Aucun commentaire:
Enregistrer un commentaire