How to store toggle button value in database php

To store the value of a toggle button in a database using PHP, you would need to follow these steps:

  1. Create a form with a toggle button.
  2. Submit the form to a PHP script.
  3. Retrieve the value of the toggle button in the PHP script.
  4. 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();
?>

Leave a comment