Spaces:
Sleeping

pde / save_scores.php
Pezh's picture
Create save_scores.php
371e253 verified
Raw History Blame Contribute Delete
1.33 kB
<?php
// Database connection
$servername = "localhost"; // Replace with your actual database server name
$username = "your_username"; // Replace with your actual database username
$password = "your_password"; // Replace with your actual database password
$dbname = "your_database"; // Replace with your actual database name
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Assuming the user's id is available in a session or passed to this script
$user_id = $_SESSION['user_id']; // Replace with your actual user identification method
// Retrieve POST data from the questionnaire form
$q1_option = $_POST['q1']; // Assuming 'q1' is the name of the first question radio button group
$q2_option = $_POST['q2']; // Assuming 'q2' is the name of the second question radio button group
$q3_option = $_POST['q3']; // Assuming 'q3' is the name of the third question radio button group
// Save scores to the database
$sql = "INSERT INTO user_scores (user_id, q1_option, q2_option, q3_option) VALUES ('$user_id', '$q1_option', '$q2_option', '$q3_option')";
if ($conn->query($sql) === TRUE) {
echo "Scores saved successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>