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
https://forums.phpfreaks.com/topic/222034-php-and-jquery-post/
Share on other sites

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.