用户向Phpmyadmin输入的SQL插入语句不起作用

时间:2019-01-24 14:44:54

标签: php mysqli mariadb

我试图建立一个网站,人们可以注册/订阅,我会将他们的电子邮件地址存储在数据库中。我在网上搜索了解决方案,但找不到任何东西

我的代码:

<html>
    <?php include_once('include/html/hoofd.php') ?>
    <body>

        <h1 id="css"> ----- </h1>
        <br><br><br>
        <ul>
            <form method="post" action="./emailverwerk.php" class="email" id="css2">
                <b><extra &nbsp;&nbsp; space >Register and we will notify you with the the next GREAT deal!</b><br>
                <br>
                Full Name: <input type="text" class="css2" name="naam" placeholder="Full name"><br>
                Email adress : <input type="email" class="css2" name="emailaddress" placeholder="Email Adress"><br>
                Email adress : <input type="email" class="css2" name="Emailaddressrepeat" placeholder="Repeat Email "><br>       
                <a href="http:/----------/emailverwerk.php"><input type ="Submit" value ="Subscribe" id="css3"><br>

                <?php
                session_destroy();
                if (isset($_SESSION["error"])) {
                    print ($_SESSION["error"]);
                }
                ?>
            </form>
        </ul>
        <ul>
            <form method="post" class="actie" id="expired1">
                <b>- Claim your free 1000 TRX here!!</b><br>
                 This is a one time offer! <br>
                 Click the link below and fill in your details to claim your free 1000 TRX!<br>
                <input type="submit" value="Expired!!" id="css3">          
            </form>
        </ul>
    </body>
</html>

还有我的SQLI代码:

<?php

session_start();
include_once ("include/database.php");
$name = $_POST["naam"];
$email = $_POST["Emailaddress"];
$emailherh = $_POST["Emailaddressrepeat"];

$sql = "INSERT INTO emaillist (naam , email)
VALUES ('".$_POST["naam"]."','".$_POST["emailaddress"]."')";

if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}

$conn->close();
}
?>

我也是一年级的学生,所以我的编程经验还不是那么完美。

2 个答案:

答案 0 :(得分:0)

提交表单时不需要您的Anchor标记,并且该标记未关闭。  

答案 1 :(得分:0)

您必须转义字符串。否则,您将禁止爱尔兰语。想想O'Brian会发生什么。它将给您带来神秘的“语法错误”。