Dear Sir,
I am making a chat project in php so i want to register session variable through jquery, and ajax method
My Code for Registering variable..
var postdata = 'username=' + username + '&password=' + password + '&first=' + first + '&last=' + last + '&mobile=' + mobile + '&email=' + email + '&dob=' + dob + '&gender=' + gender;
jQuery.ajax({
type: 'POST',
url: 'http://localhost/group/php/register.php',
data: postdata,
cache: false,
success: function(){
$.post("php/redirecting.php",
{"username":username});
window.location.replace('http://localhost/group/profile.html');
}
});
php file code redirecting.php
<?php
session_start();
$uname = $_POST['username'];
$_SESSION['user'] = $uname;
?>
Next page profile.html i want to retrive value from database...
jquery file
$(document).ready(function(){
getval();
});
function getval()
{
$.ajax({
type:"GET",
url:"http://localhost/group/php/profileedit.php",
success: function(result)
{
$("#fname").val(result);
}
});
};
profileedit.php
<pre><?php
if(isset($_SESSION['user']))
{
$uname = $_SESSION['user'];
}else
{
die('Could not connect: ' . mysql_error());
}
$link = mysql_connect('localhost','root','');
if (! $link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("groupchat",$link) or die('couldnt able to connect db');
$sql = "select fname,lname from users where username = '$uname'";
$result = mysql_query($sql,$link);
if(! $result)
{
die('Could not get data:'. mysql_error());
}
$row = mysql_fetch_array($result);
echo trim($row['fname']);
echo trim($row['lname']);
mysql_close($link);
?>
but here in the text box it could not retrive value from session variable like its not registering in session but when i give value manually its successfully retrieve value from database and fill in textbox...
please help.... suggest me ...thanks in advance..