Yeah i am sorry for my negligence in reading the guidelines prior to posting. Because this problem piss me off in my smooth learning of PHP via your wonderful book and so i posted instantly to get some helps. So here is the code for register.php and view_users.php as same as Larry's book. Have a look and please send me the suggestions. Thank you!!!
1)first one is the register.php;
<?php # register.php
$page_title = 'Register';
include('includes/header.html');
//Check if the form has been submitted:
if(isset($_POST['submitted'])){
$errors = array(); //Initialise the array
//Check for a first name:
if(empty($_POST['first_name'])){
$errors[] = 'You forgot to enter your first name';
}else{
$fn = trim($__POST['first_name']);
}
//Check for your 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';
}else{
$e = trim($__POST['email']);
}
//Check for the password and match against 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('../mysqli_connect.php');//connect to db
//Make the query:
$q = "INSERT INTO users (first_name,last_name,email,pass,registered_date) VALUES
('$fn','$ln','$e',SHA1('$p'),NOW())";
$r = @mysqli_query($dbc,$q); //Run the query
if($r){ //if it ran ok
//print the message
echo'<h1> Thank you!</h1>
<p>You are now registered. In chapter 11 you will actually be able to log in!</p><p><br/></p>';
}else{// if it didn't run ok
//public message:
echo'<h1> System Error</h1>
<p class="errors"> You could not be registered due to a system error.
We apologise for any incovenience.</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 the footer and quit the script:
include('includes/footer.html');
exit();
}else{ //Report the erros
echo'<h1>Errors!</h1>
<p class="error"> The following error(s) occured:<br/>';
foreach($errors as $msg){ //Print the each errors;
echo"-$msg<br/>\n";
}
echo'</p><p>Please try again.</p><p><br/></p>';
} //End of the if(empty($errors) IF
}//End of the main submit conditional
?>
<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');
?>
2)Second one is the view_users.php which shows some System errors and page is not displayed. i thought it has something to do with the problem in register.php
<?php # view_users.php
//This script retrieves all the records from the user table
$page_title = 'View the current users';
include('includes/header.html');
//page Header:
echo'<h1> Registered Users</h1>';
require_once('../mysqli_connect.php'); //connect to db
//Make the query
$q = "SELECT CONCAT(last_name,',',first_name)AS name, DATE_FORMAT(registered_date,
'%M %d,%Y') AS date FROM users ORDER BY registered_date ASC";
$r =@mysqli_query($dbc,$q);//Run the query
if($r){ //If it ran ok display the records
//Table header
echo'<table align="center" cellspacing="3" cellpadding="3" width ="75%">
<tr>
<td align ="left"><b> Name</b></td>
<td align = "left"><b>Date Registered</b></td></tr>';
//Fetch and print all the records
while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
echo'<tr>
<td align ="left">'. $row['name'].'</td>
<td align ="left">'.$row['date'].'</td></tr>';
}
echo'</table>'; //close the table
mysqli_free_result($r); Free up the resources
}else{ //if it didn't ran ok
//public Message:
echo'<p class="error"> The current users could not be retrieved. we apologise for the inconvience.</p>';
//Debugging Message:
echo'<p>'.mysqli_error($dbc).'<br/><br/> Query:'.$q.'</p>';
}//End of the if ($r) IF
mysqli_close($dbc); //close the database connection
include('includes/footer.html');
?>