PHP查询预先形成没有错误,但没有发布到MySQL服务器

时间:2017-08-10 01:04:32

标签: php mysql

无法将我的数据发布到MySQL服务器。寻找额外的一双眼睛,告诉我它为什么不张贴!下面我有testpost.php,允许用户输入姓名和电子邮件并将其发布到我的welcome.php页面,然后创建与我的SQL服务器的连接,该服务器在mysqli_connect.php <中设置/ p>

&#13;
&#13;
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "test";

$conn = new
mysqli($servername,$username,$password,$database);
if($conn->connect_error){
die("Connection failed:" . $conn->connect_error);
}
echo "Connected Sucessfully";
?>

  
&#13;
<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html> 

 
&#13;
<html>
<body>

<?php

require_once 'mysqli_connect.php';

$name = $_POST['name'];
$email = $_POST['email'];

$query = "INSERT INTO test_table (name,email) VALUES('$name', '$email')";
?>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"];
  ?>

</body>
</html> 
  

   
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您没有执行查询。

设置$ query后,您需要:

$ conn-&GT;查询($查询);