需要帮助在PHP中执行此SQL查询

时间:2017-01-02 14:19:51

标签: php mysql sql insert sql-insert

我在php文件中编写了一些代码来创建数据库连接,然后接收POST参数并将它们插入表中。这不会发生。请帮助。

<?php
   $con=mysqli_connect("localhost","root","","test");

   if (mysqli_connect_errno($con)) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   $username = $_POST['username'];
   $tag = $_POST['tag'];
   $id = $_POST['id'];   
   $password = $_POST['password'];
   $result = mysqli_query($con,"INSERT INTO table3 (username,tag,u_id,u_pass) VALUES ('$username','$tag','$id','$password')");
   mysqli_close($con);
?>

以下是HTML表单:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <form method="post" action="registerSession.php">
            <input type="hidden" name="username" value="admin">
            <input type="hidden" name="tag" value="yahoo">
        <input type="hidden" name="id" value="admin@yahoo.com">
            <input type="hidden" name="password" value="admin">
            <input type="submit" value="click me">
        </form>
    </body>
</html>

0 个答案:

没有答案