I have a different problem concerning chapter 9. I am using PHP version 5.4.8. I am trying to create a registration script based on page 279. I made small adjustments to suit the tables in my database, but it seems not to work. Here is how the form looks like in the bowser. I wonder why it is saying "value= value= value= value= value= value=". My full script and form is below. Many thanks for your help!
Customer Registration value= value= value= value= value= value= First Name Last Name E-Mail Username Password Repeat Password
<?php
$page_tile = 'Registration';
include "../includes/header.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors = array();
// Is first name registered?
if (empty($_POST['first_name'])) {
$errors[] = 'Please enter your first name.';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['first_name']));
}
// Is last name registered?
if (empty($_POST['last_name'])) {
$errors[] = 'Please enter your last name.';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['last_name']));
}
// Has the e-mail been entered?
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = mysqli_real_escape_string($dbc, trim($_POST['email']));
}
// If the password is missing or does not match with confirmed password?
if (!empty($_POST['pass1'])) {
if ($_POST['pass1'] != $_POST['pass2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($_POST['pass1']));
}
} else {
$errors[] = 'Please enter your password.';
}
// If the submitted data passed all the conditions:
if (empty($errors)) {
// Connect to the database.
require ('../mysqli_connect.php');
// Register the user in the database:
$q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";
$r = @mysqli_query ($dbc, $q);
if ($r) {
// Print a message:
echo 'Thank you! You are now registered. Please, log in and view our variety of products.</p>';
// If it did not run OK.
} else {
echo '<p><strong>You could not be registered due to a system error. We apologise for any inconvenience.</strong></p>';
}
// Close the database connection.
mysqli_close($dbc);
// Include the footer and quit the script:
include "../includes/footer.php";
exit();
// Report the errors.
} else {
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
}
}
?>
<div id="container" class="box">
<div id="obsah1" class="content box">
<div class="in">
<h2 class="mtop0">Customer Registration</h2>
<form id="customerregistration" method="post" action="registration.php">
<table width="80%" border="0" cellspacing="2" cellpadding="2">
<td>First Name</td>
<td><input type="text" name="first_name" id="first_name" size="45"/></td>
</tr>
value=<?php if (isset($_POST['first_name'])) echo $_POST ['first_name'];?>
<td>Last Name</td>
<td><input type="text" name="last_name" id="last_name" size="45"/></td>
</tr>
value=<?php if (isset($_POST['last_name'])) echo $_POST ['last_name'];?>
<td>E-Mail</td>
<td><input type="text" name="email" id="email" size="60"/></td>
</tr>
value=<?php if (isset($_POST['email'])) echo $_POST ['email'];?>
<td>Username</td>
<td><input type="text" name="username" id="username" size="50"/></td>
</tr>
value=<?php if (isset($_POST['username'])) echo $_POST ['username'];?>
<tr>
<td>Password</td>
<td><input name="pass1" type="password" id="pass1" size="40"/></td>
</tr>
value=<?php if (isset($_POST['pass1'])) echo $_POST ['pass1'];?>
<td>Repeat Password</td>
<td><input name="pass2" type="password" id="pass2" size="40"/></td>
</tr>
value=<?php if (isset($_POST['pass2'])) echo $_POST ['pass2'];?>
</table>
<p>
<input name="Submit" type="button" value="Submit" />
</p>
</form>
</div>
</div>
</div>
<?php include "../includes/footer.php";?>