Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created March 25, 2024 18:53
Show Gist options
  • Save AbhishekGhosh/ea533f388e1ef8d3702dea2db0c20c78 to your computer and use it in GitHub Desktop.
Save AbhishekGhosh/ea533f388e1ef8d3702dea2db0c20c78 to your computer and use it in GitHub Desktop.
store_data.php
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get water level from POST data
$waterLevel = $_POST["water_level"];
// Insert data into database
$sql = "INSERT INTO water_level (level) VALUES ('$waterLevel')";
if ($conn->query($sql) === TRUE) {
echo "Data stored successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment