I'm trying to insert dropdown values into my database but it won't insert. I'm not getting any errors either so I'm kinda confused, still new and trying to learn PHP :)
So here's a sample of the dropdown:
<div class="wrap-input100 validate-input">
<span class="label-input100" style="font-size: 17px; color: black;">I lock my computer screen when I walk away from it (Windows + L)</span>
<select class="selection-2" name="q1">
<option selected disabled hidden></option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
and here's my PHP code (LMK if you need the whole PHP code, only posted these as I thought this is where the errors come from):
if(empty($emailaddress_err) && empty($q1_err) && empty($q2_err) && empty($q3_err) && empty($q4_err) && empty($q5_err) && empty($q6_err) && empty($q7_err) && empty($q8_err) && empty($q9_err) && empty($q10_err)){
// Prepare an insert statement
$sql = "INSERT INTO employees (emailaddress, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sssssssssss", $emailaddress, $q1, $q2, $q3, $q4, $q5, $q6, $q7, $q8, $q9, $q10);
// Set parameters
$emailaddress = $emailaddress;
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
$q4 = $_POST['q4'];
$q5 = $_POST['q5'];
$q6 = $_POST['q6'];
$q7 = $_POST['q7'];
$q8 = $_POST['q8'];
$q9 = $_POST['q9'];
$q10 = $_POST['q10'];
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($link);
}
PHP code is on top of the index HTML so here's my form action:
<form class="contact100-form validate-form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" onsubmit="alert('Success!');">
and the submit button:
<button class="myButton" type="submit">Submit</button>