Jump to content

How to Update Database on the AJAX method Call.... ?


verdanmahmood

Recommended Posts

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";

}

 

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);
         }
         ....

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.