[英]Cannot POST /test.php when i am trying to enter data into database its given me this error
When I am trying to enter data into using php its give me an error Cannot POST /test.php
please how I can solve it I am trying so much but it's not working please anyone can help me to solve this problem. 当我试图输入数据到使用PHP它给我一个错误Cannot POST /test.php
请我如何解决它我是如此努力,但它没有工作,请任何人都可以帮我解决这个问题。 It is my project work 这是我的项目工作
this is my html code 这是我的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>
this is my php code 这是我的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 !";
?>
This problem usually occurs when the PHP file you're trying to POST to isn't in the same directory as the HTML file. 当您尝试POST到的PHP文件与HTML文件不在同一目录中时,通常会发生此问题。
If the PHP file is in a different directory you need to give the path to the file (either relative or absolute). 如果PHP文件位于不同的目录中,则需要提供文件的路径(相对或绝对)。 For instance for a directory structure such as 例如,对于诸如的目录结构
root
- html
- index.html
- php
- test.php
your HTML form should point to "../php/test.php"
. 您的HTML表单应指向"../php/test.php"
。
As an aside, your code is vulnerable to SQL Injection . 另外,您的代码很容易受到SQL注入攻击。 Please look into using prepared statements using PDO . 请查看使用PDO使用预准备语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.