Databases Reference
In-Depth Information
// If we don't get exactly one answer, then we have a problem
for($matchedrows=0;($tmprow = @ mysqli_fetch_array($result));$matchedrows++) $row=$tmprow;
if($matchedrows!=1)
die("We've just experienced a technical problem - ".
"please notify the administrator.");
// Does the user-supplied password match the password in the table?
if (crypt($password, substr($username, 0, 2)) != $row["password"])
{
// No, so redirect the browser to the login page with a
// message
$message = "This user exists, but the password is incorrect. ".
"Choose another username, or fix the password.";
header("Location: index.php?message=" . urlencode($message));
exit;
}
}
// Everything went OK. Start a session, store the username in a
// session variable, and redirect the browser to the gift list
// page with a welcome message.
session_start();
$_SESSION['username']=$username;
$message = "Welcome {$_SESSION['username']}! Please select gift suggestions".
" from the list to add to your shopping list!";
header("Location: list.php?message=" . urlencode($message));
exit;
}
?>
Example A-6. license.txt
Source code example for Learning MySQL
Unless otherwise stated, the source code distributed with this topic can be
redistributed in source or binary form so long as an acknowledgment appears
in derived source files.
The citation should list that the code comes from
S.M.M. (Saied) Tahaghoghi and Hugh E. Williams,
"Learning MySQL" published by O'Reilly Media.
This code is under copyright and cannot be included in any other book,
publication, or educational product without permission from O'Reilly &
Associates.
No warranty is attached; we cannot take responsibility for errors or fitness
for use.
Example A-7. list.php
<?php
// list.php: Show the user the available gifts and the gifts in
// their shopping list
// Include database parameters and related functions
require_once("db.php");
// Check if the user is logged in
 
Search WWH ::




Custom Search