Code for Login.php
<?php # login.php
// This is the login page for the site.
// Include the configuration file for error management and such.
require_once ('includes/config.inc');
// Set the page title and include the HTML header.
$page_title = 'Login';
include ('includes/header.html');
if (isset($_POST['submit'])) { // Check if the form has been submitted.
require_once ('mysqli_connect.php'); // Connect to the database.
if (empty($_POST['username'])) { // Validate the username.
$u = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your username!</font></p>';
} else {
$u = escape_data($_POST['username']);
}
if (empty($_POST['password'])) { // Validate the password.
$p = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your password!</font></p>';
} else {
$p = escape_data($_POST['password']);
}
if ($u && $p) { // If everything's OK.
// Query the database.
$query = "SELECT id, username FROM users WHERE username='$u' AND password=PASSWORD('$p')";
$result = mysqli_query ($dbc, $query);
$row = mysqli_fetch_array ($result);
if ($row) { // A match was made.
// Start the session, register the values & redirect.
$_SESSION['username'] = $row[1];
$_SESSION['id'] = $row[0];
ob_end_clean(); // Delete the buffer.
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
} else { // No match was made.
echo '<p><font color="red" size="+1">The username and password entered do not match those on file.</font></p>';
}
mysqli_close($dbc); // Close the database connection.
} else { // If everything wasn't OK.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}
} // End of SUBMIT conditional.
?>
<h1>Login</h1>
<p>Your browser must allow cookies in order to login.</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
<p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" /></p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
</fieldset></form><!-- End of Form -->
<br>
<p>Not a registered user yet? <a href="add_user.php">Click here to sign up for an account</a></P>
<?php // Include the HTML footer.
include ('includes/footer.html');
?>
Header.html
<?php # Script 17.2 - header.html
// Start output buffering and initialize a session.
ob_start();
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ultimate Video Game Connection</title>
<link rel="stylesheet" media="all" type="text/css" href="css/styles.css" />
<style type="text/css">
<!--
body,td,th {
color: #080C58;
}
-->
</style></head>
<body>
<div id="outer">
<div id="nav_bar"><img src="images/header1.jpg" width="950" height="107" alt="logo" />
<div class="container">
<ul class="nav">
<li><a href="#url">Home</a></li>
</ul>
<ul class="nav">
<li class="sub-li"><a class="sub-a" href="#url">Nintendo</a>
<ul>
<li><a href="browse_selections.php">NES</a></li>
<li><a href="browse_snes.php">Super Nintendo (SNES)</a></li>
<li><a href="#url">Gamecube</a></li>
<li><a href="#url">Game Boy Advance (GBA)</a></li>
</ul>
</li>
</ul>
<ul class="nav">
<li class="sub-li"><a class="sub-a" href="#url">Microsoft</a>
<ul>
<li><a href="#url">Email</a></li>
<li><a href="#url">Telephone</a></li>
<li><a href="#url">Online Form</a></li>
<li><a href="#url">Snail Mail Address</a></li>
</ul>
</li>
</ul>
<ul class="nav">
<li class="sub-li"><a class="sub-a" href="#url">Sony</a>
<ul>
<li><a href="#url">Email</a></li>
<li><a href="#url">Telephone</a></li>
<li><a href="#url">Online Form</a></li>
<li><a href="#url">Snail Mail Address</a></li>
</ul>
</li>
</ul>
<ul class="nav">
<li class="sub-li"><a class="sub-a" href="#url">Sega</a>
<ul>
<li><a href="#url">Email</a></li>
<li><a href="#url">Telephone</a></li>
<li><a href="#url">Online Form</a></li>
<li><a href="#url">Snail Mail Address</a></li>
</ul>
</li>
</ul>
<ul class="nav">
<li class="sub-li"><a class="sub-a" href="#url">Other</a>
<ul>
<li><a href="#url">Email</a></li>
<li><a href="#url">Telephone</a></li>
<li><a href="#url">Online Form</a></li>
<li><a href="#url">Snail Mail Address</a></li>
</ul>
</li>
</ul>
<ul class="nav">
<li class="sub-li"><a class="sub-a" href="#url">About</a>
<ul>
<li><a href="#url">About Us</a></li>
<li><a href="#url">FAQ</a></li>
</ul>
</li>
</ul>
<ul class="nav">
<li><a href="#url">Contact</a></li>
</ul>
<ul class="nav">
<li><a href="#url">View Cart</a></li>
</ul>
</div></div><br />
<div id="main_content">
<table width="875" border="0" cellspacing="2" cellpadding="5">
<tr valign="top">
<td width="35%" valign="top">
<div id="xsnazzy">
<b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b>
<div class="xboxcontent">
<h2>Enter A Game Name to Search</h2>
<center><p>
<form method="post" action="search.php">
<input type="text" name = "select_name" id="search" class="search_box_font" value="Search for a game!" onfocus="if (this.value == 'Search for a game!') this.value = '';" onblur="if (this.value == '') this.value = 'Search for a game!';" maxlength="255" />
<input type="image" class="button" src="images/btn_search.png" />
</form></p>
</div>
<b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b></center>
</div>
<div id="xsnazzy">
<b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b>
<div class="xboxcontent">
<p>
<?php
// Welcome the user (by name if they are logged in).
if (isset($_SESSION['username'])) {
echo '<h2>Welcome, ';
echo "{$_SESSION['username']}!</h2>";
echo '<p><br /><a href="logout.php">Logout</a>';
echo '<br /><a href="discounts.php">Available Coupon Codes</a>';
}
else {
echo '<h2>Welcome, Guest ';
//echo "{$_SESSION['username']}!</h2>";
echo '<br /><a href="login.php">Click here to sign in</a> ';
}
?> </p>
</p>
</div>
<b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b>
</div>
<div id="xsnazzy">
<b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b>
<div class="xboxcontent">
<h2>Sign Up for the Newsletter</h2>
<form method="post" action="search.php">
<center><input type="text" name = "select_name" id="search" class="search_box_font" value="Enter Your E-Mail" onfocus="if (this.value == 'Enter Your E-Mail') this.value = '';" onblur="if (this.value == '') this.value = 'Enter Your E-Mail';" maxlength="255" />
<input type="image" class="button" src="images/mail-icon.png" /></center>
</div>
<b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b>
</div>
</td>
<td width="65%">
Search.php
<?php # Script 17.5 - browse_selections.php
// This page displays the available selections (products).
// Set the page title and include the HTML header:
$page_title = 'Browse the Video Games';
include ('includes/header.html');
$searchNotFound = false;
$name = '';
if (!isset($_POST['select_name'])) {
//page is opened directly - set not found flag on true
$searchNotFound = true;
} else {
$name = trim($_POST['select_name']);
require_once ('mysqli_connect.php');
// Default query for this page:
$q = "SELECT productid, productName, price, image_name, systemName
FROM products, systems
WHERE systems.systemid = products.systemid
AND productName LIKE '%".$name."%'
ORDER BY systemName ASC;";
$num_results = 0;
// Are we looking at a particular selection?
if (isset($_GET['productid']) && is_numeric($_GET['pid']) ) {
$pid = (int) $_GET['pid'];
if ($pid > 0) { // Overwrite the query:
echo "PID: $pid";
$q = "SELECT productid, productName, price, image_name, systemName FROM products, systems, genre
WHERE productid = $pid AND systems.systemid = products.systemid";
}
}
// Create the table head:
echo '<table border="0" cellspacing="2" cellpadding="4">';
// Display all the selections, linked to URLs:
$result = mysqli_query ($dbc, $q);;
// If the result is not empty
$num_results = mysqli_num_rows($result);
if( $num_results ) {
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
// Display each record:
echo "\t<tr>
<td width=\"40%\" align=\"middle\"><a href=\"view_selection.php?pid={$row['productid']}\"><p>{$row['productName']}</a></p></td>
<td rowspan=\"3\" align=\"right\" width=\"60%\"><img src=images2/{$row['image_name']} width=75></td>
</tr>\n
\t<tr>
<td align=\"middle\"><p>{$row['systemName']}</p></td>
</tr>\n
\t<tr>
<td align=\"middle\"><p>\${$row['price']}</p></td>
</tr>\n
</tr>\n";
} // End of while loop.
// Free up the resources.
mysqli_free_result($result);
} else {
// wanted string not found - set not found flag on true
$searchNotFound = true;
}
// Close the database connection.
mysqli_close($dbc);
if( $searchNotFound ) {
echo '<p>No result matching the search criterion.</p>';
}
}
include ('includes/footer.html');
?>

New Topic/Question
Reply




MultiQuote







|