doujiling4377 2019-04-14 18:13
浏览 138

当我试图将数据输入数据库时​​,不能POST /test.php给我这个错误

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. It is my project work

this is my html code

<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
 $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 !";

?>
  • 写回答

1条回答 默认 最新

  • doujiao3074 2019-04-14 18:32
    关注

    This problem usually occurs when the PHP file you're trying to POST to isn't in the same directory as the HTML file.

    If the PHP file is in a different directory you need to give the path to the file (either relative or absolute). For instance for a directory structure such as

    root
      - html
        - index.html
      - php
        - test.php
    

    your HTML form should point to "../php/test.php".

    As an aside, your code is vulnerable to SQL Injection. Please look into using prepared statements using PDO.

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法