PHP表单没有插入到mySQL数据库中

时间:2016-10-06 22:35:48

标签: php mysql post

大家好,谢谢,如果你能告诉我我需要帮助的错误,请各位帮助我

<?php 
    $servername = "localhost";   $username = "root"; $password = ""; 
    $dbname = "kurd";
    mysql_connect("localhost","root","","kurd") or die ("not connect data base");
    mysql_select_db("kurd") or die ("no found table"); 
    if(isset($_POST['submit'])){
        $name = $_POST['name'];$lastname = $_POST['lastname'];
        $password =_POST['password'];
        $query =" INSERT INTO kurdstan (name,lastname,password) VALUES ('$name','$lastname','$password')";
        if(mysql_query($query)){
            echo "<h3>THANKS FOR INSERT DATA GOOD LUCK</h3>";
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

在您的代码中添加else

if(mysql_query($query)){
   echo "<h3>THANKS FOR INSERT DATA GOOD LUCK</h3>";
}

导致,

if(mysql_query($query)){
   echo "<h3>THANKS FOR INSERT DATA GOOD LUCK</h3>";
}
else {
   echo 'MYSQL Error: ' . mysql_error();
}

您可能会看到错误而非您的消息,这可能有助于您追踪问题。

注意

mysql扩展程序现已弃用,您应使用mysqli http://php.net/manual/en/book.mysqli.php或PDO http://php.net/manual/en/book.pdo.php。您还应该阅读SQL注入 - 您的数据在用于查询字符串之前需要转义。