hey... just wondering if anyone could help me with what i thought was supposed to be an easy code.. hehe...
it's just 3 pages of code: 1) index.php where it will check for page 2) which validates whether or not there is a registered session and if there isn't, it'll lead you to page 3) which is a logon page
I have a database (mysql) named "testdb" with a table called "members" with four columns ("nick" "password" "fname" and "lname")
now my trouble is...
1) if i load up the index.php it'll tell me that "The page cannot be displayed" as if the page didn't exist... if i take out the:
require("validate.php");
then the page works fine (gets data with no problems)
2) when i load up the login page by itself (never got the page to lead me into the login obviously)... i fill in the nick and password... but no matter what i do.... it just loads the login page.... even with the correct nick and password
any help would be great... thanx.. : )
here's the code:
1) index.php
<?php
require("validate.php");?>
<html>
<head>
<title>Database</title>
</head>
<body>
<h2>Current People</h2>
<table border="1">
<tr>
<td>Name</td>
</tr>
<tr>
<?php
$conn = mysql_connect();
mysql_select_db("testdb",$conn);
$query = "SELECT * FROM members";
$results = mysql_query($query, $conn);
while ($row=mysql_fetch_array($results)) {
print "
<tr>
<td>$row[fname] $row[lname]</a>
</td>
</tr>";
}mysql_close($conn);
?>
</table>
</body>
</html>
2) validate.php
<?php
session_start();
if(!(session_is_registered("userNick"))) {
header("Location:[url]http://[/url]$HTTP_HOST/cc/login.php");
exit();
}
?>
3) login.php
<?php
if(!($conn=mysql_connect())) {
print "<BR>Error connecting...<BR>";
exit();
}
if(!mysql_select_db("testdb", $conn)) {
print "<BR>Error selecting datable.";
print mysql_errno($conn). " ". mysql_error($conn);
exit();
}
session_start();
if($nickname!="") {
$sql="SELECT * From members
WHERE nick='$nickname'";
$result=mysql_query($sql, $conn);
if(($row=mysql_fetch_array($result)) && ($password==$row[password]
&& $password!="")) {
$userNick=$nickname;
session_register("userNick");
mysql_close($conn);
header("Location:[url]http://[/url]$HTTP_HOST/cc/index.php");
exit();
} else {
mysql_close($conn);
header("Location:[url]http://[/url]$HTTP_HOST/cc/login.php");
exit();
}
}
mysql_close($conn);
?>
<Html>
<Head>
<Title>Login</Title>
</Head>
<Body>
<H3>Please Login</H3>
<Form Action="<?php print $PHP_SELF;?>" Method="post">
<Table>
<TR>
<TD>Nick</TD>
<TD><Input Type="Text" Name="nickname" Size="20"></TD>
</TR>
<TR>
<TD>Password</TD>
<TD><Input Type="Password" Name="password" Size="20"></TD>
</TR>
<TR>
<TD Colspan="2" Align="Center"><Input Type="Submit" Value="Login"></TD>
</TR>
</Table>
</Form>
</Body>
</Html>
<Html>
<Head>
<Title>Login</Title>
</Head>
<Body>
<H3>Please Login</H3>
<Form Action="<?php print $PHP_SELF;?>" Method="post">
<Table>
<TR>
<TD>Nick</TD>
<TD><Input Type="Text" Name="nickname" Size="20"></TD>
</TR>
<TR>
<TD>Password</TD>
<TD><Input Type="Password" Name="password" Size="20"></TD>
</TR>
<TR>
<TD Colspan="2" Align="Center"><Input Type="Submit" Value="Login"></TD>
</TR>
</Table>
</Form>
</Body>
</Html>