javascript - php form not working no matter input, php script alert not working -


so have been searching questions "randomly redirects index.php" , "form not submitting correctly" none of questions seem address problem thinking maybe problem specific one. (may contain more 1 error).

basically have login page supposed redirect register.php if username , password not match of in database, , redirect index.php if both username(email) , password matches.

login.php

<?php include "header.php"; ?>   <!--follow header.php-->  <div class="ui centered grid" id="loginbox"> <div class="ui inverted segment">     <form class="ui inverted form" action="login.php" method="post" enctype="multipart/form-data">         <div class="two fields">             <div class="required field">                 <label>username</label>                 <input placeholder="username" type="text" name="log_email" required/>             </div>             <div class="required field">                 <label>password</label>                 <input placeholder="password" type="text" name="log_password" required/>             </div>         </div>         <button class="ui submit button" name="login" type="submit"><a href="index.php">log in</a></button>         <button class="ui button"><a href="register.php">register</a> </button>     </form> </div> </div>  <!--continue footer_form.php--> <?php  if(isset($_post['login'])){ $log_email = $_post['log_email']; $log_password = $_post['log_password'];  $sel_log = "select * customers email ='$log_email' , password ='$log_password'"; $run_log = mysqli($mysqli,$sel_log); $check_customer = mysqli_num_rows($run_log); if($check_customer==0){     echo"<script>alert('please register first!')</script>";     header("location: register.php");     exit; } if($check_customer>0){     echo"<script>alert('logged in successfully!')</script>";     header("location: index.php");     exit; } }   include "footer_form.php" ?> 

tldr; problems are: 1) alert script not seem working both cases of if 2) once in while when clicking "log in" on login.php page, stays on same page, goes index.php, inconsistent, regardless of input in username , password.

database side naming , connections correct.

edit: php form problem has been solved friends below in comment section. want share answer solved script problem.

    if($check_customer==0){     echo"<script>alert('please register first!');window.location='register.php'</script>";     exit; } 

using code above solved problem seems alert script , header not compatible, using window.location solved gracefully.

your submit button goes index.php:

<button class="ui submit button" name="login" type="submit">   <a href="index.php">log in</a> </button> 

remove anchor:

<button class="ui submit button" name="login" type="submit">log in</button> 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -