删除不起作用的数据库条目


Delete a database entry not working

我有两个页面,第一个页面显示MySQL数据库中特定字段的所有项目:

DatabaseEntries.php

<?php
include('connect.php');
$result = mysqli_query($db, "SELECT * FROM names") 
    or die(mysqli_error($db));  

echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Firstname</th> <th>lastname</th> <th>Email</th><th></th> ";

while($row = mysqli_fetch_array( $result )) {
    // echo out the contents of each row into a table
    echo "<tr>";
    echo '<td>' . $row['firstname'] . '</td>';
    echo '<td>' . $row['lastname'] . '</td>';
    echo '<td>' . $row['email'] . '</td>';
    echo '<td><a href="delete.php?email=' . $row['email'] . '">Delete</a></td>';
    echo "</tr>"; 
} 
?>

第二页包含删除功能:

删除.php

 <?php
 include('connect.php');
 // check if the 'id' variable is set in URL, and check that it is valid
 if (isset($_GET['email']) )
 {
 // get id value
 $email = $_GET['email'];
 // delete the entry
 $result = mysqli_query($db, "DELETE FROM names WHERE email=$email")
 or die(mysqli_error($db)); 
 // redirect back to the view page
 header("Location: DatabaseEntries.php");
 }
 else
 // if id isn't set, or isn't valid, redirect back to view page
 {
 header("Location: Error.php");
 }
?>

我在尝试从数据库中删除项目时遇到以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com' at line 1

有人能告诉我为什么吗?该怎么解决?

感谢

$email 周围添加quotes

DELETE FROM names WHERE email='$email'