In the first IF I have two open braces that’s why I had this error.
I did some changes on the script
I replace the
if (session_is_registered("valid_user"))
with
if(isset($_SESSION['valid_user']))
in the psscript.php
if (session_is_registered("valid_user"))
{
echo "You are logged in as: $valid_user <br>";
echo "<a href=\"logout.php\">Log out</a><br>";
}
else
Now the script it not showing any error but I can’t log in with the password and the user name. The script stops to the first if and it echo out “You have not entered all the required details”
if (!$first_name || !$last_name)
{
echo "You have not entered all the required details . <br>";
exit;
}
I am not sure if the form sends the values to the pscript.php
<?php
session_start();
if (!$first_name || !$last_name)
{
echo "You have not entered all the required details . <br>";
exit;
}
require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
$connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
mysql_select_db($db_name, $connection);
$query = "select * from guestsbook "
."where name='$first_name' "
." and comment='$last_name'";
$result = mysql_query($query, $connection);
if (mysql_num_rows($result) > 0 )
{
$valid_user = $first_name;
}
?>
<http>
<head>
<title> Script </title>
</head>
<body>
<?php
if(isset($_SESSION['valid_user']))
{
echo "You are logged in as: $valid_user <br>";
echo "<a href=\"logout.php\">Log out</a><br>";
}
else
{
if (isset($first_name))
{
echo "Could not log you in";
}
else
{
echo "You are not logged in.<br>";
}
}
?>
</body>
</html>
Thank you !!!