What am I doing wrong?
The following script does not stop a blank id being passed on, despite the check.
It also just pulls out the same record from the database no matter what id is input.
<?php
include 'db.inc';
include 'clean.inc';
$DBName = "NewDatabase";
$TableName = "Feedback2";
//connect to DB server
$Link = mysql_connect($Host, $User, $Password)
OR die("Could not connect to database");
//select DB
mysql_select_db($DBName, $Link)
OR die(mysql_error());
$id = clean($id, 5);
//Has an id been provided?
//if so, retrieve all customer details for editing.
if (!empty($id))
{
$query = "SELECT * from $TableName";
if ($result = @($query, $Link))
{
$row = mysql_fetch_array($result);
//other processing
}
else
{
echo mysql_error();
}
}
//reset $Array since we areloading from the feedback2 table
$Array= array();
//Load all the form variables with newdatabase data
$Array["Company"] = $row["Company"];
$Array["Logo"] = $row["Logo"];
$Array["Strapline"] = $row["Strapline"];
$Array["Activity"] = $row["Activity"];
$Array["Contact"] = $row["Contact"];
$Array["Phone"] = $row["Phone"];
$Array["Mobile"] = $row["Mobile"];
$Array["Email"] = $row["Email"];
$Array["Add1"] = $row["Add1"];
$Array["Add2"] = $row["Add2"];
$Array["Add3"] = $row["Add3"];
$Array["Add4"] = $row["Add4"];
$Array["Postcode"] = $row["Postcode"];
$Array["Text"] = $row["Text"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style type="text/css">
<!--
td {font-family: arial; font-size: 10pt; }
h1 {font-family: arial; font-size: 14pt; }
h3 {font-family: arial; font-size: 10pt; }
//-->
</style>
<title>Company details</title>
</head>
<body bgcolor="white">
<form method="post" action=example.6-8.php">
<!--example6.8 is from book and uses $id to identify row to be updated>
<!-- its code is also in this directory. It is not called until you enter fields & submit-->
<h1> Company details</h1>
<h3>Please change any details below and submit: </h3>
<table>
<col span="1" align="right">
<tr>
<td><input type ="hidden" name="id" value="<?echo $ID;?>"></td>
</tr>
<tr>
<td><font>Company:</font></td>
<td><input type="text" name="Company"
value="<? echo $Array["Company"];?>" size=50></td>
</tr>
<tr>
<td><font>Logo:</font><</td>
<td><input type="text" name="Logo"
value="<? echo $Array["Logo"];?>" size=50></td>
</tr>
<tr>
<td><font>Strapline:</font></td>
<td><input type="text" name="Strapline"
value="<? echo $Array["Strapline"];?>" size=50></td>
</tr>
<tr>
<td><font>Activity:</font></td>
<td><input type="text" name="Activity"
value="<? echo $Array["Activity"];?>" size=50></td>
</tr>
<br><br>