Jump to content

php and jquery post


doddsey_65

Recommended Posts

I am using jQuery to post the contents of a html form to a php file which process them then returns a result. jQuery then catches this result and either logs you in or displays an error.

 

This is working fine. It logs me in if i specify the right details and doesnt if i specify wrong details. However when i am redirectd to the home page I have a line which says welcome {username}. However username displays an undefined.

 

Here is the form(cut down)

 

<form name="login_form" id="login_form" method="post">
<input id="user_name" class="field" type="text" name="user_name_field" />
</form>

 

next is the jquery which posts the form data(cut down):

 

jQuery("#login_form").submit(function()
{
jQuery.post("./modules/login_process.php",{ 
user_name:jQuery("#user_name").val() } ,function(data)
{ 
if (data == 1)
{
document.location="./index.php";
}
else
{ 
}
});
});

 

then is the login_process.php

 

if (isset($_POST['user_name']))
{
$user_name = asf_escape(trim($_POST['user_name']));
$login_query = mysql_query("SELECT *
							FROM ".TBL_PREFIX."members
							WHERE user_username = '$user_name'
							") or die (mysql_error());
$result = mysql_num_rows($login_query);

if ($result != 0)
	{
		$_SESSION['logged_in'] = 1;
		$_SESSION['user_username'] = $user_name;

		echo $result;
	}
	else
	{
		if(!empty($user_name))
		{
			$error .= "No Records Found for Username: $user_name ";
		}
		echo $error;
	}

 

As I said it works fine logging in, the username is checked against the database but when i return the session which is equal to the posted username i get "undefined".

 

Anyone see where i am going wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.