我有一个表单输入字段,用户在其中编写电子邮件以订阅简报。我必须验证电子邮件,并检查它是否已经在我的数据库中。现在所有的检查都是正确的,但是当它确实需要将电子邮件插入我的数据库时,它会在我的sql语句中给出一个SYNTAX错误。多次检查,调整它但我找不到问题。我甚至只是在我的PhPMyAdmin中添加了一行并复制粘贴了执行的代码。依然没有。 因此,如果我测试它,它验证电子邮件,然后我尝试了一个已经在我的数据库中的电子邮件,它正确地给出了它已经在数据库中的输出,但是当它必须转到其他地方时,它给了我和错误:
您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在第1行的“email@email.com”附近使用正确的语法
我的代码如下:
<form method="post" action="#anker" class="footerform" id="anker">
<input type="email" value="" name="fldEmail" class="brief" id="nieuwsbrief" placeholder="Nieuwsbrief Email" >
<input type="submit" value="Schrijf me in!" name="subscribe" id="nieuwsbriefsubmit" class="btn"></div>
<?php
require('db.php');
if (isset($_POST["subscribe"])) {
if ($_POST["fldEmail"]=="") {
echo "<p>error: Vul het veld in aub</p>";
}else {
$fldEmail=$_POST['fldEmail'];
$fldEmail =filter_var($fldEmail, FILTER_SANITIZE_EMAIL);
$fldEmail= filter_var($fldEmail, FILTER_VALIDATE_EMAIL);
if (!$fldEmail) {
echo "<p>Je email-adres is niet correct</p>";
} else {
$fldEmail = stripslashes($fldEmail);
$fldEmail = mysqli_real_escape_string($connection, $fldEmail);
$testquery = "SELECT fldEmail FROM nieuwsbrief WHERE fldEmail = '$fldEmail'";
$result = mysqli_query($connection, $testquery) or die(mysqli_error($connection));
$rows = mysqli_num_rows($result);
if ($rows > 0) {
echo "emailadres zit al in onze databank";
} else {
$query = "INSERT INTO nieuwsbrief (fldEmail) VALUES '$fldEmail'";
$result2 = mysqli_query($connection, $query) or die(mysqli_error($connection));
echo "<p>Bedankt om je op de nieuwsbrief in te schrijven</p>";
}
}
}
}
?>
</form>
答案 0 :(得分:1)