Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 php session, need guidance

views
     
TSlucashii
post Feb 1 2006, 04:44 PM, updated 20y ago

Getting Started
**
Junior Member
288 posts

Joined: Nov 2004
From: msia/uk


<?php
session_start();
include("connect.php");

$match = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);

if ($num_rows <= 0) {
echo "Sorry, $username might not be register or password entered incorrect.<br>";
echo "<a href=login.html>Try again</a>";
exit;

} else
{
session_register('username');
$site_name = $session_register;
echo "Login Successful<br>";
echo "Continue to the <a href=member.php>members</a> section.";
}
?>

I've tried to use session with this simple code when pass to the member page i try to echo it out like this

<?php
session_start();
echo hello $site_name ;
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<p>Members Area Welcome! </p>
</body>

</html>

I get an error on the second line of echo hello $site_name ;

is there anything wrong it?Thanks~
TSlucashii
post Feb 2 2006, 10:09 PM

Getting Started
**
Junior Member
288 posts

Joined: Nov 2004
From: msia/uk


thanks for the reply but i still cant get it to work echoing out the username~
TSlucashii
post Feb 2 2006, 11:38 PM

Getting Started
**
Junior Member
288 posts

Joined: Nov 2004
From: msia/uk


login.php
======
session_start();
include("connect.php");

$match = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);

if ($num_rows <= 0) {
echo "Sorry, $username might not be register or password entered incorrect.<br>";
echo "<a href=login.html>Try again</a>";
exit;

} else
{
session_register('username');
$_SESSION["username"] = $username;
echo "Login Successful<br>";
echo "Continue to the <a href=member.php>members</a> section.";
}
==========
after login page
==========
<?php
session_start();
echo "hello ".$_SESSION["username"];

?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<p>Members Area Welcome! </p>
</body>

</html>

?>

This is the code suggested by snow~i am thinking maybe there is a need to store username in an array?but my knowledge is limited at the time~any help is much appreciated thank~ smile.gif

This post has been edited by lucashii: Feb 2 2006, 11:40 PM
TSlucashii
post Feb 3 2006, 12:48 AM

Getting Started
**
Junior Member
288 posts

Joined: Nov 2004
From: msia/uk


i figure out that i need

$username = $_POST['username'];

which to pass the username from the database~
TSlucashii
post Feb 5 2006, 11:49 PM

Getting Started
**
Junior Member
288 posts

Joined: Nov 2004
From: msia/uk


need to ma fan pro here again...i wanna retrieve and display id from my $table...i've been trying out for hours @_@ can any pro help?thanks~
TSlucashii
post Feb 6 2006, 10:40 PM

Getting Started
**
Junior Member
288 posts

Joined: Nov 2004
From: msia/uk


thanks seventh7 for the help its working now...but now i need help with mysql~

$_SESSION['sid'] = $id // my session id

$insert = mysql_query("insert into movie values ('NULL', '$id','".$_POST['title']."', '".$_POST['year']."')")
or die("Could not insert data because ".mysql_error());

i want to insert the $id into my movie table but i guess there is something wrong with my statement...any advice would be helpful =) thanks~

 

Change to:
| Lo-Fi Version
0.0157sec    1.18    6 queries    GZIP Disabled
Time is now: 23rd December 2025 - 11:11 PM