簡體   English   中英

當我試圖將數據輸入數據庫時​​,不能POST /test.php給我這個錯誤

[英]Cannot POST /test.php when i am trying to enter data into database its given me this error

當我試圖輸入數據到使用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 !";

?>

當您嘗試POST到的PHP文件與HTML文件不在同一目錄中時,通常會發生此問題。

如果PHP文件位於不同的目錄中,則需要提供文件的路徑(相對或絕對)。 例如,對於諸如的目錄結構

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

您的HTML表單應指向"../php/test.php"

另外,您的代碼很容易受到SQL注入攻擊。 請查看使用PDO使用准備語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM