Hey, I'm new here and I got this code that I'm trying to get to work to make a members section on my website. But I can't get it to work. It will never connect to the database which is MySQL. Heres the code if anyone can help that'd be great.
1st Page:
code:
<?php // accesscontrol.php
include("common.php");
include("db.php");
session_start();
if(!isset($uid)) {
?>
<html>
<head>
<title> Please Log In for Access </title>
</head>
<body>
<h1> Login Required </h1>
<p>You must log in to access this area of the site. If you are
not a registered user, <a href="signup.php">click here</a>
to sign up for instant access!</p>
<p><form method="post" action="<?=$PHP_SELF?>">
User ID: <input type="text" name="uid" size="8"><br>
Password: <input type="password" name="pwd" SIZE="8"><br>
<input type="submit" value="Log in">
</form></p>
</body>
</html>
<?php
exit;
}
session_register("uid");
session_register("pwd");
dbConnect("sessions");
$sql = "SELECT * FROM user WHERE
userid = '$uid' AND password = PASSWORD('$pwd')";
$result = mysql_query($sql);
if (!$result) {
error("A database error occurred while checking your ".
"login details.\\nIf this error persists, please ".
"contact soundboard@sbcglobal.net.");
}
if (mysql_num_rows($result) == 0) {
session_unregister("uid");
session_unregister("pwd");
?>
<html>
<head>
<title> Access Denied </title>
</head>
<body>
<h1> Access Denied </h1>
<p>Your user ID or password is incorrect, or you are not a
registered user on this site. To try logging in again, click
<a href="<?=$PHP_SELF?>">here</a>. To register for instant
access, click <a href="signup.php">here</a>.</p>
</body>
</html>
<?php
exit;
}
$username = mysql_result($result,0,"fullname");
?>
2nd Page:
code:
<?php // common.php
function error($msg) {
?>
<html>
<head>
<script language="JavaScript">
<!--
alert("<?=$msg?>");
history.back();
//-->
</script>
</head>
<body>
</body>
</html>
<?
exit;
}
?>
3rd Page:
code:
<?php // signup.php
include("common.php");
include("db.php");
if (!isset($submitok)):
// Display the user signup form
?>
<html>
<head><title>New User Registration</title></head>
<body>
<h3>New User Registration Form</h3>
<p><font color=orangered size=+1><TT><B>*</B></TT></font>
indicates a required field</p>
<form method=post action="<?=$PHP_SELF?>">
<table border=0 cellpadding=0 cellspacing=5>
<tr>
<td align=right>
<p>User ID</p>
</td>
<td>
<input name=newid type=text maxlength=100 size=25>
<font color=orangered size=+1><TT><B>*</B></TT></font>
</td>
</tr>
<tr>
<td align=right>
<p>Full Name</p>
</td>
<td>
<input name=newname type=text maxlength=100 size=25>
<font color=orangered size=+1><TT><B>*</B></TT></font>
</td>
</tr>
<tr>
<td align=right>
<p>E-Mail Address</p>
</td>
<td>
<input name=newemail type=text maxlength=100 size=25>
<font color=orangered size=+1><TT><B>*</B></TT></font>
</td>
</tr>
<tr valign=top>
<td align=right>
<p>Other Notes</p>
</td>
<td>
<textarea wrap name=newnotes rows=5 cols=30></textarea>
</td>
</tr>
<tr>
<td align=right colspan=2>
<hr noshade color=black>
<input type=reset value="Reset Form">
<input type=submit name="submitok" value=" OK ">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
else:
// Process signup submission
hookUpDb('sessions');
if ($newid=="" or $newname=="" or $newemail=="") {
error("One or more required fields were left blank.\\n".
"Please fill them in and try again.");
}
// Check for existing user with the new id
$sql = "SELECT COUNT(*) FROM user WHERE userid = '$newid'";
$result = mysql_query($sql);
if (!$result) {
error("A database error occurred in processing your ".
"submission.\\nIf this error persists, please ".
"contact soundboard@sbcglobal.net.");
}
if (mysql_result($result,0,0)>0) {
error("A user already exists with your chosen userid.\\n".
"Please try another.");
}
$newpass = substr(md5(time()),0,6);
$sql = "INSERT INTO user SET
userid = '$newid',
password = PASSWORD('$newpass'),
fullname = '$newname',
email = '$newemail',
notes = '$newnotes'";
if (!mysql_query($sql))
error("A database error occurred in processing your ".
"submission.\\nIf this error persists, please ".
"contact soundboard@sbcglobal.net.");
// Email the new password to the person.
$message = "G'Day!
Your personal account for the SoundBoard Web Site
has been created! To log in, click Login in the navigational panel.
Your personal login ID and password are as
follows:
User ID: $newid
Password: $newpass
You aren't stuck with this password! You can
change it at any time after you have logged in.
If you have any problems, feel free to contact me at
<soundboard@sbcglobal.net>.
-Alex
SoundBoard Webmaster
";
mail($newemail,"Your Password for the Project Website",
$message, "From:Alex <soundboard@sbcglobal.net>");
?>
<html>
<head><title> Registration Complete </title></head>
<body>
<p><strong>User registration successful!</strong></p>
<p>Your User ID and Password have been emailed to
<strong><?=$newemail?></strong>, the email address
you just provided in your registration form. To log in,
click <a href="index.php">here</a> to return to the login
page, and enter your new personal User ID and Password.</p>
</body>
</html>
<?php
endif;
?>
4th Page:
code:
<?php include("accesscontrol.php"); ?>
<html>
<head>
<title> Members-Only Page </title>
</head>
<body>
<p>Welcome, <?=$username?>! You have entered a members-only area
of the site. Don't you feel special?</p>
</body>
</html>/
5th Page (and last)
code:
<?php // db.php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
function hookUpDb($db="sessions") {
global $dbhost, $dbuser, $dbpass;
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");
if ($db!="" and !@mysql_select_db($db))
die("The site database is unavailable.");
return $dbcnx;
}
?>
I know the answer will probably be something really simple but oh well. And as you can see it supposed to always stay at one URL and never change. So any help would be greatly appreciated.
Latez