首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当我尝试向数据库中输入数据时,无法发布/test.php,它给出了这个错误

当我尝试向数据库中输入数据时,无法发布/test.php,它给出了这个错误
EN

Stack Overflow用户
提问于 2019-04-15 02:13:37
回答 1查看 64关注 0票数 0

当我试图输入数据到使用php,它给我一个错误的Cannot POST /test.php,请给我如何解决它我尝试了这么多,但它不工作,请任何人可以帮助我解决这个问题。这是我的项目工作

这是我的html代码

代码语言:javascript
复制
<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代码

代码语言:javascript
复制
<?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 !";

?>
EN

回答 1

Stack Overflow用户

发布于 2019-04-15 02:32:26

当您尝试发布的PHP文件与HTML文件不在同一目录中时,通常会出现此问题。

如果PHP文件位于不同的目录中,则需要提供该文件的路径(相对路径或绝对路径)。例如对于目录结构,例如

代码语言:javascript
复制
root
  - html
    - index.html
  - php
    - test.php

您的HTML表单应该指向"../php/test.php"

顺便说一句,您的代码容易受到SQL Injection的攻击。请研究使用PDO的预准备语句。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55678483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档