【发布时间】:2017-07-25 02:17:42
【问题描述】:
所以我一直在尝试创建一个简单的 HTML 表单,它将用户信息提交到本地 MYSQL 数据库。当我尝试运行它时,我得到“无法发布 /test/addperson.php”。我已经尝试了许多其他发布的解决方案,但它们似乎都不起作用。
HTML
<!DOCTYPE html>
<html>
<body>
<h2>User Database</h2>
<br>
<form action="test/addperson.php" method="post">
<p>First Name: </p>
<input type="text" name="first_name">
<p>Last Name: </p>
<input type="text" name="last_name"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
PHP
<?php
$connect = mysql_connect("localhost:3306","root", "password");
if(!connect){
die('Connection Failed: ' . mysql_error());
}
mysql_select_db("Users", $connect);
$user_info = "INSERT INTO employees (first_name, last_name) VALUES ('$_POST[first_name]', '$_POST[last_name]')";
if(!sql_query($user_info, $connect)){
die('Error' . mysql_error());
}
echo "Your information was added to the database.";
mysql_close($connect);
?>
【问题讨论】:
-
请stop using
mysql_*functions。 These extensions 已在 PHP 7 中被删除。了解 PDO 和 @987654325 的 prepared 语句@ 并考虑使用 PDO,it's really pretty easy。 -
Cannot POST /test/addperson.php 你确定这是文件所在的位置吗?您是否检查了错误日志以获取更多信息?