简体   繁体   English

我的HTML表单未发布到我的数据库中,我的php是否有问题?

[英]My HTML form is not posting to my database, is there something wrong with my php?

I am trying to get my HTML form to post to my data base but I get nothing. 我试图将我的HTML表单发布到数据库中,但是我什么也没得到。 I am not bothered about the security side of things at the moment I would just like it functional. 目前,我只是想让它发挥作用,所以我对事物的安全性方面并不感到困扰。 I have looked all over the web for a solution and at most of the similar problems on here. 我在网上寻找解决方案,并在此找到了大多数类似的问题。 I am probably just missing something stupid. 我可能只是想念一些愚蠢的东西。

HTML 的HTML

  <form action="booking.php"  id="booking" name="booking" method="post">
       Let us know what you would like and when and we will get back to you 
       to confirm<br>
         <label for="name">Name:</label>
         <input type="text" id="name" name="name"><br>
         <label for="email">Email:</label>
         <input type="email" name="email" id="email" required>`

PHP 的PHP

<?php

define('db_database', 'database');
define('db_user_name', 'username');
define('db_password', 'password');
define('db_server_name', 'server');

$dbconnect = mysqli_connect(db_server_name, db_user_name, db_password, 
db_database);

if (!$dbconnect) {
die('Could not connect: ' . mysqli_error());
}

echo 'Connected!';

$db_selected = mysqli_select_db($dbconnect, db_database);


     $name = $_POST['name'];

     $mysqli = "INSERT INTO booking (name) VALUES ($name)"; 

?>

MySQL returned an empty result set (ie zero rows). MySQL返回一个空结果集(即零行)。 (Query took 0.0004 seconds.) (查询花费了0.0004秒。)

  1. Make sure that the name attribute in the input tag from your name is defined as name like: <input type="text" name="name"> Without this you can't access. 确保将您名称中输入标签中的名称属性定义为以下名称: <input type="text" name="name">如果没有此属性,您将无法访问。 Check if you get the value of the submitted form like: echo $_POST["name"] 检查是否获得提交表单的值,例如: echo $_POST["name"]

I would recommend to get the $name variable in the SQL-Query like this: INSERT INTO booking (name) VALUES ('$name') 我建议像这样在SQL查询中获取$ name变量: INSERT INTO booking (name) VALUES ('$name')

If it's not working after all, try to execute the query like this: 如果毕竟不起作用,请尝试执行以下查询:

$result = mysqli_query($dbconnect, $mysqli);

(instead of your $db_selected part) (而不是您的$db_selected部分)

I hope I can help. 希望我能帮上忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM