To store the value of a toggle button in a database using PHP, you would need to follow these steps:
- Create a form with a toggle button.
- Submit the form to a PHP script.
- Retrieve the value of the toggle button in the PHP script.
- Store the value in the database.
Here’s an example:
// HTML form
// store_toggle.php
connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
// Prepare and execute the database query
$sql = “INSERT INTO toggle_table (value) VALUES (‘$toggleValue’)”;
if ($conn->query($sql) === TRUE) {
echo “Toggle button value stored successfully.”;
} else {
echo “Error storing toggle button value: ” . $conn->error;
}
// Close the database connection
$conn->close();
?>