我有一个文件signupform.html,其中包含以下代码:
<!DOCTYPE html>
<html>
<body>
<form action = "signup.php" method = "post">
USERNAME:<input type="text" name="uname"><br/>
PASSWORD:<input type="password" name="pswd"><br/>
<input type ="submit">
</form>
</body>
</html>
请注意,表单的action属性调用signup.php
并且文件signup.php具有以下代码:
<?php
require('db.php');
$username = mysqli_real_escape_string($myConn,$_POST['uname']);
$password = mysqli_real_escape_string($myConn,$_POST['pswd']);
$query= 'SELECT COUNT(*) FROM $database WHERE USERNAME=$username;';
$result=mysqli_query($myConn,$query);
$array=mysqli_fetch_array($result);
if(!$query)
echo 'FAILED:'.mysqli_error();
if($array[0]==1)
echo 'A user with this username already exists! Please select a different username.';
else if($array[0]==0)
{
mysqli_query('INSERT INTO $database VALUES ($username , $password)');
echo 'Congratulations! You have been signed up successfully.';
}
?>
db.php具有以下代码:
<?php
$host = 'localhost';
$uname='root';
$pswd='';
$myDB='signup';
$myConn = new mysqli($host,$uname,$pswd);
$database = mysqli_select_db($myConn,$myDB);
?>
现在,我面临的问题是,当我打开signupform.html并输入用户名和密码时,就会下载signup.php文件。为什么会这样呢?
最佳答案
如果您正在运行XAMPP / WAMP,是否已将文件signup.html放在htdocs目录中?如果没有,请放在htdocs / signup form.html下
关于php - HTML表单的action属性中的目标文件是否被下载而不是被解析?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29084101/