当我试图输入数据到使用php,它给我一个错误的Cannot POST /test.php
,请给我如何解决它我尝试了这么多,但它不工作,请任何人可以帮助我解决这个问题。这是我的项目工作
这是我的html代码
<html>
<head>
<title>Login and Registration Form </title>
<link rel="stylesheet" href="style.css" >
</head>
<body>
<div class ="login-page">
<div class ="form">
<form class="login-form">
<h1>Log In </h1>
<input type="text" placeholder="Email id"/>
<input type="password" placeholder="Password"/>
<button type="submit">Log In </button>
<p class="message">Not Registered?<a href="#"> Signup</a></p>
</form>
<form class="register-form" action="test.php" method="post">
<h1>Sign up </h1>
<input type="text" name="name" required placeholder="User Name"/>
<input type="email" name="email" required placeholder="Email id"/>
<input type="password" name="password" required placeholder="Password"/>
<button name="subject" type="submit" value="Register">Sign up</button>
<p class="message">Already Registered?<a href="#">Login</a></p>
</form>
</div>
</div>
<script src='https://code.jquery.com/jquery-3.4.0.min.js'></script>
<script>
$('.message a').click(function(){$('form').animate({height:"toggle", opacity : "toggle"}, "slow");
});
</script>
</body>
</html>
这是我的php代码
<?php
$name = $_POST['name'];
$email =$_POST['email'];
$password = $_POST['password'];
$con = mysqli_connect('localhost','root','','registeration');
$query = "INSERT INTO `signup`(`name`, `email`, `password`) VALUES ('$name','$email','$password')";
$run=mysqli_query($con,$query);
if($run==TRUE)
echo "Data Insert Successfully";
else
echo "Error !";
?>
发布于 2019-04-15 02:32:26
当您尝试发布的PHP文件与HTML文件不在同一目录中时,通常会出现此问题。
如果PHP文件位于不同的目录中,则需要提供该文件的路径(相对路径或绝对路径)。例如对于目录结构,例如
root
- html
- index.html
- php
- test.php
您的HTML表单应该指向"../php/test.php"
。
顺便说一句,您的代码容易受到SQL Injection的攻击。请研究使用PDO的预准备语句。
https://stackoverflow.com/questions/55678483
复制相似问题