所以我正在尝试创建一个文本框,供用户输入他们的电子邮件并将其插入数据库。
我有以下文件:
index.html
<form method="post" action="sql.php">
Email Address:
<input name="email" type="text" required placeholder="Enter A Valid Email Address">
<button type ="submit" name="submit" value="send"> SEND </button>
</form>
sql.php
<?php
if (isset($_POST['submit'])) {
$email=$_POST['email'];
mysql_select_db('mydatabase');
$sqlinsert = "INSERT INTO mytable (email) VALUES ('$email')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 record added to database";
}
?>
当我点击提交按钮时,出现错误:
"POST /sql.php" Error (404): "Not found"
我已经仔细检查以确保两个文件都在同一目录中,php 文件确实存在,我还尝试将 action="sql.php"
更改为 action="/sql.php"
。我真的不知道我的代码有什么问题。
最佳答案
我能够在本地主机上运行您的文件,它对我来说工作正常。你的情况可能有两件事
文件扩展名:Maker 用户您的文件扩展名很好,应该是 sql.php 而不是 sql.php.txt 等
您正在服务器上测试您的代码,即 http://localhost/test/index.html
而不是直接在浏览器中打开文件
关于php - MySQL 404 错误,找不到 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41375632/