verdanmahmood Posted July 20, 2011 Share Posted July 20, 2011 I have two pages.. login.php(client side page) and dologin.php(login verification page) Now the Problem is I want to UPDATE the status of a user to "login" whenever he logged in... What am i doing wrong although the LOGGED IN SUCCESSFUL message is available.... ? ? ? Here is my login.php Code... <form id="login_form" name="form" method="post" action="doLogin.php"> <br /><br /><div class="form_error"> </div> <p> <label for="email" class="content_login">Email :</label> <input type="text" id="email_login" name="email" /> </p> <p> <label for="password" class="content_login">Password :</label> <input type="password" id="password_login" name="password" /> </p> <input style="margin-right:5px; margin-left:125px" type="submit" class="content_login" value="Sign In" id="login_btn"/> <input type="reset" id="close" onclick="this.form.reset();" class="content_login" value="Cancel"/> </form> AJAX. $(document).ready(function() { $(".window #login_btn").click(function() { var action = $("#login_form").attr('action'); var form_data = { email: $("#email_login").val(), password: $("#password_login").val(), is_ajax: 1 }; $.ajax({ type: "POST", url: action, data: form_data, success: function(response) { if(response == 'success'){ $(".form_error").html("You Have Loged In... !"); $(".window").slideUp('slow') $('#mask').fadeOut(500); setTimeout("location.reload(true);",1300) } else $(".form_error").html("Invalid username and/or password."); } }); return false; }); Dologin.php code... if(isset($is_ajax) && $is_ajax) { $email = $_REQUEST['email']; $password = md5($_REQUEST['password']); $sql = mysql_query("SELECT * FROM user WHERE email='$email' and password='$password'"); $id=mysql_fetch_array($sql); $id=$id['user_id']; $count = mysql_num_rows($sql); if ($count==1){ $status=mysql_query("UPDATE user SET status='login' WHERE user_id='$id'"); echo "success"; die();} if($count!=1) echo "fail"; } Quote Link to comment https://forums.phpfreaks.com/topic/242469-how-to-update-database-on-the-ajax-method-call/ Share on other sites More sharing options...
TeNDoLLA Posted July 20, 2011 Share Posted July 20, 2011 Should not this be if(isset($is_ajax) && $is_ajax) Like this if(isset($_POST['is_ajax']) && $_POST['is_ajax']) Since you are sending the is_ajax variable as POST variable to the doLogin.php. Quote Link to comment https://forums.phpfreaks.com/topic/242469-how-to-update-database-on-the-ajax-method-call/#findComment-1245326 Share on other sites More sharing options...
verdanmahmood Posted July 20, 2011 Author Share Posted July 20, 2011 Logged in successfull...... but the "status" is still there.... ... want the status to be updated as "login".... Quote Link to comment https://forums.phpfreaks.com/topic/242469-how-to-update-database-on-the-ajax-method-call/#findComment-1245328 Share on other sites More sharing options...
TeNDoLLA Posted July 20, 2011 Share Posted July 20, 2011 Have you tried adding mysql_error to the queries to see if they fail and why they fail (add that also to the other query you have there)? $sql = mysql_query("SELECT * FROM user WHERE email='$email' and password='$password'") or die(mysql_error()); Then in the response just alert the response from the AJAX call to see the error msg's if there were any. $.ajax({ type: "POST", url: action, data: form_data, success: function(response) { alert(response); } .... Quote Link to comment https://forums.phpfreaks.com/topic/242469-how-to-update-database-on-the-ajax-method-call/#findComment-1245334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.