Hi,
Okay you shouldn't use session_register. It works but you can see here:
http://uk2.php.net/manual/en/function.session-register.php
This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
There is another more fundamental error you couldn't have known about which is that you're storing the password in the session: session data can be captured and checked so you should ideally never store a username or a password in it without first encoding them in some way.
So, your code as presented but altered would be:
// Session start or create the site_sessions.inc.php type file and include it
session_start();
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['login_valid'] = TRUE;
header("location:login_success.php");
}
else
{
// Make doubly sure it's not TRUE left over from a previous login or something.
$_SESSION['login_valid'] = FALSE;
echo "Wrong Username or Password";
}
Then for login_success:
// Or use include_once on a file with session_start in it
session_start();
// Better to check if we have a TRUE value to do what we want rather
// than checking on a wrong value to escape out.
if ((isset($_SESSION['login_valid']) && ($_SESSION['login_valid'] == TRUE))
{
<table width="398" border="1" cellspacing="1">
<td width="71">add news</td>
<td width="117">edit / delete news</td>
<td width="122">go to last news</td>
<td width="75">logout</td>
</tr>
</table>
<p>Login Successful! Please choose one of the options above.</p>}
else
{
header("location:login.php");
}
Okay, so for each of your three linked to PHP files, add news, edit / delete news and go to last news, you adopt exactly the same structure as for login_succes aboe but you replace the menu code with the page code.
You can use include functionality to encapsulate parts of this code to make it easier.