Databases Reference
In-Depth Information
// Yes; display information about the connection error
die("Error " . mysqli_connect_errno($connection) .
" : " .mysqli_connect_error($connection));
else
// No; display the error information for the active connection
die("Error " .mysqli_errno($connection) . " : "
.mysqli_error($connection));
}
// Secure the user data by escaping characters and shortening the
// input string
function clean($input, $maxlength)
{
// Access the MySQL connection from outside this function.
global $connection;
// Limit the length of the string
$input = substr($input, 0, $maxlength);
// Escape semicolons and (if magic quotes are off) single and
// double quotes
if(get_magic_quotes_gpc())
$input = stripslashes($input);
$input = mysqli_real_escape_string($connection, $input);
return $input;
}
// Check if the user is logged in. If not, send them to the login
// page
function logincheck()
{
session_start();
if (empty($_SESSION["username"]))
{
// redirect to the login page
header("Location: index.php");
exit;
}
}
?>
Example A-3. disclaimer
<?php
echo "\n<table width=\"60%\">";
echo "\n<tr><td>\n<hr />";
echo "\n<i>This is not really a wedding registry.
It's a system that demonstrates the concepts of web database systems,
and is downloadable source code that you can use freely under this
<A href=\"license.txt\">license</a>. It pretends to
allows wedding guests to log in, view a list of gifts wanted
by the bride and groom, and reserve gifts that they plan to
purchase by putting them on a shopping list.</i>";
 
Search WWH ::




Custom Search