PHP操作文件未在表单提交中调用

时间:2019-04-01 04:28:21

标签: php html form-submit

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

以下是代码

index.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的顶部,并尝试了自调用action=""。甚至没有用。

1 个答案:

答案 0 :(得分:0)

删除此行,因为验证错误后,它将进入index.php页面

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