I have a table with four columns, and one of them holds user-entered email addresses. I'm trying to use PHP/SQL to delete an email from the "email" column, but only if it matches with what the users enter in my "removeemail" form.
Here's my code for the table:
<?php
require_once("connectvars.php");
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "CREATE TABLE email_list (
id INT AUTO_INCREMENT,
first_name VARCHAR(20),
last_name VARCHAR(20),
email VARCHAR(60),
PRIMARY KEY (id) )";
...
?>
The remove email form:
<form method="post" action="removeemail.php">
<label for="email">Email address:</label><br/>
<input type="text" id="email" name="email" /><br/>
<input type="submit" name="submit" value="Remove" />
</form>
And my php to remove the email:
<?php
require_once('connectvars.php');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$email = $_POST['email'];
$query = "DELETE FROM email_list WHERE email = $email";
mysqli_query($dbc, $query) or die('Error querying database.');
echo 'Customer removed: ' . $email;
mysqli_close($dbc);
?>
I keep getting the or die error for some reason every time I try to delete an email. Any help would be greatly appreciated!