Hi, I am hoping someone has run into this problem and can point me in the right direction. I have a simply opt out form and I want it to update the database to show the email address has requested to opt out of mailing. However, when I submit the request, I get “Record updated successfully” but the database has not actually been updated.
My input field for the opt out option is <input type="checkbox" id="checkbox" name="optout">
They will just put in their email <input type="text" id="email" name="email" placeholder="email">
My database for my opt out column type is varchar(5) the column name is optout.
My insert code is below.
`// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$email = $_POST['email'];
$optout = $_POST['optout'];
// update data in mysql database
$sql = "UPDATE mailinglist ". "SET optout = '$optout'".
"WHERE email = '$email'" ;
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>`
I have been trying all kinds of different solutions online but nothing seems to be working. Where am I going wrong with this. Thank you.