How can the data from selected checkboxes and entered prices be effectively stored in a database table using PHP?
To store data from selected checkboxes and entered prices in a database table using PHP, you can first retrieve the values from the checkboxes and input fields, sanitize the data to prevent SQL injection, and then insert the data into the database table using SQL queries.
// Retrieve values from checkboxes and input fields
$checkbox_values = $_POST['checkbox']; // assuming checkboxes have name attribute 'checkbox[]'
$price = $_POST['price'];
// Sanitize the data
$price = filter_var($price, FILTER_SANITIZE_NUMBER_FLOAT);
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Insert data into database table
$sql = "INSERT INTO table_name (checkbox_values, price) VALUES ('$checkbox_values', '$price')";
$conn->query($sql);
// Close the database connection
$conn->close();