Hey Everyone,
I'm having trouble creating a login page for my database.
Whenever I enter the correct username and password I receive this error message:
Warning: require_once(../mysql_connect.
php) [
function.require-once]: failed to open stream: No such file or directory in
c:\Inetpub\wwwroot\new site\ropdunpw.php on line
200
Fatal error: require_once() [
function.require]: Failed opening required '../mysql_connect.
php' (include_path='.;C:\php5\pear') in
c:\Inetpub\wwwroot\new site\ropdunpw.php on line
200
The
php connect file is outside the main directory for security.
My
php code is as follows:
- PHP: Select all
<?php
if (isset($_POST['submit'])) {
require_once ('../mysql_connect.php');
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
}
$message = NULL;
if (empty($_POST['username'])) {
$u = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$u = escape_data($_POST['username']);
}
if (empty($_POST['password'])) {
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
$p = escape_data($_POST['password']);
}
if ($u && $p) { // If everything's OK.
$query = "SELECT user_id FROM users WHERE username='$u' AND password=PASSWORD('$p')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) {
// Start the session, register the values & redirect.
session_start();
//$_SESSION['first_name'] = $row[1];
$_SESSION['user_id'] = $row[0];
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "./index.php");
exit();
} else {
$message = '<p>The username and password entered do not match those on file.</p>';
}
mysql_close();
} else {
$message .= '<p>Please try again.</p>';
}
}
$page_title = 'Login';
//include ('../templates/header.inc');
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend class="main">Enter your information in the form below:</legend>
</br>
<p class="main"><b>User Name:</b> <input type="text" name="username" size="18" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
<p class="main"><b>Password:</b> <input type="text" name="password" size="20" maxlength="20"<?php if (isset($_POST['password'])) echo $_POST['password']; ?> /></p>
</br>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
</fieldset></form>
I've been stuck on this forever.
Any help would be great!
cheers
zig.