php - 表单数据向mySQL数据库提交空数据

标签 php mysql forms

我制作了一个表格,我希望所有数据都转到 mySQL 数据库(使用 PHPmyAdmin)。这是我的表格。

<html>
<head>

</head>
<body>
<form method="post" action="submit.php">
Interviewer <input type="text" name="interviewer"><br>
Position <input type="text" name="position"><br>
Interview Date <input type="text" name="interview_date"><br>
Candidate <input type="text" name="candidate"><br>
communication <input type="text" name="communication"><br>
appearace <input type="text" name="appearance"><br>
computer skills <input type="text" name="computer_skills"><br>
business knowledge <input type="text" name="business_knowledge"><br>
comments <input type="text" name="comments"><br>

<button type="submit">Submit</button>



</form>


</body>
</html>

所有这些都转到这里的 submit.php 文件:

  <?php



$interviewer = (isset($_GET["interviewer"]) ? $_GET["interviewer"] : null);
$position = (isset($_GET["position"]) ? $_GET["position"] : null);
$interview_date = (isset($_GET["interview_date"]) ? $_GET["interview_date"] : null);
$candidate = (isset($_GET["candidate"]) ? $_GET["candidate"] : null);
$communication = (isset($_GET["communication"]) ? $_GET["communication"] : null);
$appearance = (isset($_GET["appearance"]) ? $_GET["appearance"] : null);
$computer_skills = (isset($_GET["computer_skills"]) ? $_GET["computer_skills"] : null);
$business_knowledge = (isset($_GET["business_knowledge"]) ? $_GET["business_knowledge"] : null);
$comments = (isset($_GET["comments"]) ? $_GET["comments"] : null);

$conn = mysqli_connect("localhost", "root", "");
if($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
mysqli_select_db($conn, "human_resources") or die(mysqli_error()); 




$sql = mysqli_query($conn, "INSERT INTO human_resources (interviewer, position, interview_date, candidate, communication, appearance, computer_skills, business_knowledge, comments) VALUES ('$interviewer', '$position', '$interview_date', '$candidate', '$communication', '$appearance', '$computer_skills', '$business_knowledge', '$comments') ") or die(mysqli_error($conn)); 



$result = mysqli_query($conn,$sql) or die( mysqli_error($conn) );
echo mysql_error();

mysqli_close($conn);
?>

我添加了错误消息以查看我哪里出错了,但是没有显示任何错误消息,并且该表仍然将空数据打印到我的表中。我不清楚它可能是什么。

最佳答案

您需要在 PHP 脚本中使用 $_POST 而不是 $_GET。如果您不确定表单输入的方式,请使用 $_REQUEST

关于php - 表单数据向mySQL数据库提交空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26917119/

相关文章:

javascript - Javascript 和 AJAX 问题 - 选择表单的事件监听器在更改时不起作用?

javascript - 防止 bootstrap-3 模态在表单发生变化时关闭

c# - 在不创建 100 个表的情况下存储来自表单的数据 : ASP. NET 和 SQL Server

php - MYSQL Order By 2 rows depending on 2 other rows IDS

javascript - PHP 数组被传递给 javascript 函数但没有执行任何操作

MySql 选择连续行中的最大行数

mysql - Master-Master Mysql复制中log-bin文件大小不同

php - 如何将两个表字段名称与mysql中的另一个值进行比较?

php - 如何传递参数以从 phpspec 构建?

sql - PostgreSQL GROUP BY 与 MySQL 不同?