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

时间:2022-10-28 15:01:00

Having trouble with getting my data to post to MySQL server. Looking for an extra set of eyes to tell me why it's not posting! Below I have testpost.php which allows the user to enter in a name and email and post it to my welcome.php page which then creates a connection to my sql server which is set up in mysqli_connect.php

将数据发布到MySQL服务器时遇到问题。寻找额外的一双眼睛告诉我为什么它不发布!下面我有testpost.php,允许用户输入名称和电子邮件并将其发布到我的welcome.php页面,然后创建与我的sql server的连接,该服务器在mysqli_connect.php中设置

<?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";
?>

  
<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> 

 
<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> 
  

   

1 个解决方案

#1


1  

You're not executing your query .

您没有执行查询。

After setting $query you need:

设置$ query后,您需要:

$conn->query($query);

$ conn->查询($查询);

#1


1  

You're not executing your query .

您没有执行查询。

After setting $query you need:

设置$ query后,您需要:

$conn->query($query);

$ conn->查询($查询);