Write a PHP page where you press a button and a value is entered into data base table
Then write a python or c script that reads the first line of the table
On button 1 must be entered into the table
Off then a 0 must be entered
Use update SQL queries instead of insert
<?php
$conn = mysqli_connect("127.0.0.1", "root", "", "test");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
else{
echo "Connected to the successful!";
$data = $_REQUEST['one_value'];
$query = "INSERT INTO `test`(`value_0_1`) VALUES ('$data')";
$sql = "UPDATE test SET value_0_1=1 WHERE id=2";
if(mysqli_query($conn, $query)){
echo "Inserted successfully!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Inserting data to database</h1>
<form method="POST" action="connect_to_db">
<div name="one_value">1</div>
<div name="zero_value">1</div>
<input type="submit" value="Submit">
</form>
</body>
</html>
Comments
Leave a comment