larry i used the script in your book title PHP 6 and MySQL 5 for Dynamic web sites chapter 8, the registration script did not work for me rather i'm getting ' could not connect to MySQL: Access denied for user 'username'@'localhost' (using password: YES) ' and i try debugging it by making sure that MySQL server is running by starting my MySQL and it started i even created another database with it name user but to no avial but i was able to login to PHPMYADMIN . i'm using MYSQL version 5.5.17 apache 2.2.21 PHP 5.2.17 phpmyadmin 3.4.7.1 OS window 7 this is the code for mysqli_connect
<?php
// this file contains the database access information.
DEFINE ('DB_USER', 'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');
// make the connection
$bdc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('could not connect to MySQL: ' . mysqli_connect_error() );
?>
this is the code for the registration
<?php # register.php
$page_title = 'Register';
include ('includes/header.html');
// check if the form has been submitted:
if (isset($_POST['submitted']))
{
$errors = array(); // initialize an error array.
// check for a first name:
if (empty($_POST['first_name']))
{$errors[] = 'you forget to enter your first name.';
}
else
{
$fn = trim($_POST['first_name']);
}
// check for a last name:
if (empty($_POST['last_name']))
{
$errors[] = 'You forgot to enter your last name.';
}
else
{
$ln = trim($_POST['last_name']);
}
// check for the email address :
if (empty($_POST['email']))
{
$errors[] = 'You forgot to enter your email address.';
}
else
{
$e = trim($_POST['email']);
}
// check for a password and match agaist the confirmed password:
if (!empty($_POST['pass1']))
{
if ($_POST['pass1'] != $_POST['pass2'])
{
$errors[] = 'Your password did not match the confirmed password.';
}
else
{
$p = trim($_POST['pass1']);
}
}
else
{
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors))
{
// if everything is ok
// register the user in the database
require_once
('includes/mysqli_connect.php'); //connect to the database.
// make the query:
$q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";
$r = @mysqli_query ($dbc, $q); //run the query
if ($r)
{ //if it ran ok
// print a message:
echo '<h1>Thank you!</h1>
<p>You are now registered. go to your mail to confirm the registration then you can be able to log in!</p><p><br /></p>';
}
else
{ // if it did not run ok
// public message:
echo '<h1>System Error</h1>
<p class="error"> You could not be registered due to a system error. We apologize for any inconvinience.</p>';
// debugging message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
} // end of if ($r) IF
mysqli_close($dbc); // close the database connection.
// include the footer and quit the script:
include ('includes/footer.html');
exit();
}
else
{ // report the error
echo '<h1>error!</h1>
<p class="error">The following error(s) occured:<br />';
foreach ($errors as $msg)
{ //print each error
echo " $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
} // end of if (empty ($errors)) IF .
} // End of the main submit conditonal.
?>
<h1>Register</h1>
<form action="register.php" method="post">
<p>First name: <input type="text"
name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
<p>Password:
<input type="password" name="pass1" size="10" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('includes/footer.html');
?>
please any help will be appreciated