首页 > 解决方案 > 表单提交时未调用php操作文件

问题描述

在 php 表单提交中未调用操作文件。我发现这里发生了同样的问题,但没有正确的答案。

以下是代码,

索引.php

<form action="form_submit.php" method="POST" class="form-group">
  <div>
    <label>Email address</label>
    <input type="email" name="login_email" class="form-control" placeholder="Enter email">
    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" name="login_pw" class="form-control" id="InputPassword1" placeholder="Password">
  </div>

  <button type="submit" name="submit" value="submit" class="btn btn-primary"><i class ="fa fa-lock">&nbsp;</i>Submit</button>
</form>

form_submit.php

<?php
echo "entered";
$con=mysqli_connect("localhost","root","","inventory");

if(isset($_POST['submit']) && $_SERVER["REQUEST_METHOD"] == "POST"){
    $username=$_POST['login_email'];
    $password=$_POST['login_pw'];
    $query="select * from userlogin where username='$username' and password='$password'";
    $result=mysqli_query($con,$query);
    if(mysqli_num_rows($result)==1)
    {
        header("location:hello.php");
    }
    else
    {
        echo"<script>alert('wrong password or user name if you lost your password please contact service provider')</script>";
        echo"<script>window.open('index.php','_self')</script>";
    }
}
?>

至少echo顶部的form_submit.php没有显示。我尝试将提交代码放在顶部index.php并尝试 self-call action=""。它甚至没有用。

标签: phphtmlform-submit

解决方案


删除这一行,因为在验证错误之后它会出现在 index.php 页面上

echo"<script>window.open('index.php','_self')</script>"; from 

推荐阅读