Example.8-5.php help
Posted: Sun Sep 05, 2010 10:06 am
I am new to php. I was working my way through the PHP and MySQL book by Hugh E. William and David Lane and I hit an issue that I can not figure out with Example.8-5.php .
When this line runs the $status comes back as empty.
$status = mysqlclean($_GET, "status", 1, $connection);
How can I debug this to see where the problem is?
mySQLClean
When this line runs the $status comes back as empty.
$status = mysqlclean($_GET, "status", 1, $connection);
How can I debug this to see where the problem is?
Code: Select all
<?php
require "db.inc";
require_once "HTML/Template/ITX.php";
if (!($connection = @ mysql_connect("127.0.0.1", "root", "")))
die("Could not connect to database");
$status = mysqlclean($_GET, "status", 1, $connection);
$template = new HTML_Template_ITX("./templates");
$template->loadTemplatefile("example.8-6.tpl", true, true);
switch ($status)
{
case "T":
$phonebook_id = mysqlclean($_GET, "phonebook_id", 5, $connection);
if (!empty($phonebook_id))
{
if (!mysql_select_db("telephone", $connection))
showerror();
$query = "SELECT * FROM phonebook WHERE
phonebook_id = {$phonebook_id}";
if (!($result = @mysql_query ($query, $connection)))
showerror();
$row = @ mysql_fetch_array($result);
$template->setCurrentBlock("success");
$template->setVariable("SURNAME", $row["surname"]);
$template->setVariable("FIRSTNAME", $row["firstname"]);
$template->setVariable("PHONE", $row["phone"]);
$template->parseCurrentBlock();
break;
}
case "F":
$template->setCurrentBlock("failure");
$template->setVariable("MESSAGE", "A database error occurred.");
$template->parseCurrentBlock();
break;
default:
$template->setCurrentBlock("failure");
$template->setVariable("MESSAGE", "You arrived here unexpectedly.");
$template->parseCurrentBlock();
break;
}
$template->show();
?>
Code: Select all
<?php
// This file is the same as example 6-7, but includes mysqlclean() and shellclean()
$hostName = "127.0.0.1";
//$databaseName = "winestore";
$databaseName = "telephone";
$username = "root";
$password = "";
function showerror()
{
print "Error, world";
//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;
}
?>