简体   繁体   English

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

[英]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.

相关问题 为什么我在尝试发布到表单时收到无法发布 /api/ 错误? - Why am I getting a Cannot POST /api/ error when trying to post to a form? 我正在尝试使用 npm 下载压缩 webpack 插件,但它给我错误 - I am trying to download compression webpack plugin with npm but its giving me error 我正在尝试使用 ajax POST 方法从 html 页面将数据发送到我的 PHP 页面,但它给出错误,注意:未定义索引: - I am trying to send data to my PHP page from html page using ajax POST method but it give error ,Notice: Undefined index: 对 Node JS 很陌生,我正在尝试发布到特定请求,但它让我出错 - Quite new to Node JS and I am trying to post to a specific request but it get me error 我正在尝试使用AngularJS发布数据 - I am Trying to Post Data Using AngularJS 如何在使用时在导航栏上显示真实的网址 - How to show real url on the navigation bar when using <a href=“#” onclick=“funtion('test.php')”> Ajax警报错误(在home /../ test.php中找不到致命错误类) - Ajax alert error (Fatal error Class not found in home/../test.php) 反应当我试图进入嵌套的 object 时,提取会抛出一个未定义的错误 - React When i am trying to get into a nested object the fetch throws me an undefined error 我正在尝试获取一个动态表单,之后需要使用 PHP 将其数据插入数据库 - I am trying to get a dynamic form after which its data needs to be inserted in the DB using PHP 我正在尝试在 firebase 数据库上推送数据,但我收到此错误“无法读取属性“推送””,谁能告诉我我做错了什么? - I'm trying to push data on firebase database but I'm getting this error 'Cannot read property "push" ', can anyone tell me what I'm doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM