php header forwarding issue using Ajax

Form:-

  <form  name="form"> 
                    <div class="formfieldContainer">
                        <label> Email :</label>
                                                      <div class="login_wrapper loginContainer">
                                                          <span> </span>
                                                        <input type="email" id="email" required name="user_email" autofocus="autofocus" placeholder="Enter Email Address"/>
                                                    </div>
                                            </div>
                    <div class="formfieldContainer">
                        <label> Password :</label>
                        <input type="password" name="user_password" placeholder="Enter Password"/>
                    </div>

                    <input type="button" name= "submit" value="submit" id="submit_login"/>

                </form>

AJAX:-

$("#submit_login").click(function(){
       var username=$('input[name=user_email]').val();
       var password=$('input[name=user_password]').val();        

         $.ajax({
                type: "POST",                    
                url: "newExam.php", 
                data:{name: username,
                       pwd: password},
                       cache: false,                          
                success: function(dataa) {
                   if(dataa)
                   {
                       console.log(dataa);   
                      if(dataa==0)
                      {  $('form').effect( "shake" ); $('p.error').show(); $("#submit_login").val('Login')
                       alert('nodata');
                       }


                    else if(dataa==1){
                    window.location.href="user.php";
                        }
                     }
                 }
              });// ajax
});

PHP:-

<?php  
include('db.php');
$email_php = $_POST['name'];  
 $pwd_php=$_POST['pwd'];
 $sql = "select name from user where email='$email_php' and  password='$pwd_php'";  
$result = mysqli_query($conn,$sql);  
 $num_rows=  mysqli_num_rows($result);
if($num_rows>0){     
   $_SESSION['login_user']= $email_php;       
   echo '1';
 }
 else{  
echo '0';
  }
  ?>

I need the page to redirect to user.php when logged in successfully. But i am getting the following error:

Notice: Undefined index: name in C:xampphtdocsdemonewExam.php on line 3

Notice: Undefined index: pwd in C:xampphtdocsdemonewExam.php on line 4

How to overcome it?


Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.