Hi I am fairly new to PHP. I'm currently learning from the O'Reilly book Web Database Applications. The example in the book doesn't work and I can't figure out why. It should work by providing a link when I load example.6-12.php into the the browser. When clicked that link passes the parameters into example.6-13.php which prints the results of those two print statements that should have been passed to the server and back. I'm sure example.6-13.php should have a $connection = mysql_connect(hostname, user, password) function to make it work. As I see it there is no code to even connect to the server. This code is directly from the books website webdatabasebook.com. Any ideas??
Example.6-12.php
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Explore Wines</title>
</head>
<body bgcolor="#ffffff">
Explore all our
<a href="example.6-13.php?regionName=All&wineType=All"> wines</a>
<br>Explore our
<a href="example.6-13.php?regionName=All&wineType=Red"> red wines</a>
<br>Explore our
<a href="example.6-13.php?regionName=Riverland&wineType=Red"> premium
reds from the Riverland</a>
<br>
<a href="index.html">Home</a></body>
</html>
Example.6-13.php
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Parameters</title>
</head>
<body>
<?php
require "db.inc";
print "regionName is {$_GET["regionName"]}\n";
print "<br>wineType is {$_GET["wineType"]}\n";
?>
</body>
</html>
db.inc file
<?php
// This file is the same as example 6-7, but includes mysqlclean() and shellclean()
$hostName = "127.0.0.1";
$databaseName = "winestore";
$username = "myUserName";
$password = "myPassword";
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
function mysqlclean($array, $index, $maxlength, $connection)
{
if (isset($array["{$index}"]))
{
$input = substr($array["{$index}"], 0, $maxlength);
$input = mysql_real_escape_string($input, $connection);
return ($input);
}
return NULL;
}
function shellclean($array, $index, $maxlength)
{
if (isset($array["{$index}"]))
{
$input = substr($array["{$index}"], 0, $maxlength);
$input = EscapeShellArg($input);
return ($input);
}
return NULL;
}
?>