Everything works the way it should except that the data is being displayed three times on the screen... See below

Here is the PHP code that calls it...
Code: Select all
<?php
if ($_SERVER['REQUEST_METHOD'] != "POST") //looks to see if a button wasn't pressed
{
include "search.html.php";
}
else //looking to see if the edit button has been hit from edit.html.php
{
foreach($_POST as $name => $_POST['name'])
if('Edit' === substr($name, 0, 4)) //looks to see if the word 'Edit' is in the name field of the button
{
$name = $_POST['name'];
$trimmed = trim($name, 'Edit #');
$sql = 'SELECT pages.id, category.cat, manufacturer.manu, pages.pagename, pages.retailprice,
pages.salesprice, pages.upc, pages.sku, pages.caption, pages.pagename, image.name FROM pages
INNER JOIN category ON pages.categoryid = category.id
INNER JOIN image ON pages.imageid = image.id
INNER JOIN manufacturer ON pages.manufactureid = manufacturer.id WHERE pages.id = "'. $trimmed .'"';
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'No Pages Found.';
include 'error.html.php';
exit();
}
$row = mysqli_fetch_array($result);
include 'edit.html.php';
}
else
{
$pagetable = NULL;
$pageinfo = array();
if(!empty($_POST['searchid']) || (!empty($_POST['pagename']))) //looks to see if either search field is populated
{
//begins to generate search string
$sql = "SELECT pages.id, category.cat, manufacturer.manu, pages.pagename FROM pages
INNER JOIN category ON pages.categoryid = category.id
INNER JOIN manufacturer ON pages.manufactureid = manufacturer.id WHERE ";
if(!empty($_POST['searchid']))
{
$searchid = ($_POST['searchid']);
$sql .= "pages.id = ".$_POST['searchid']."";
}
if(!empty($_POST['searchid']) && (!empty($_POST['pagename'])))
{
$sql .= " and ";
}
if(!empty($_POST['pagename']))
{
$sql .= "pages.pagename = ".$_POST['pagename']." ";
$pagename = ($_POST['pagename']);
}
$result = mysqli_query($link, $sql);
if (!$result)
{
include 'searchres.html.php';
$error = 'No Pages Found.';
include 'error.html.php';
exit();
}
$pagetable = "<table border='1'><TR><TD WIDTH=150 BGColor='#00FF00'>Page ID</TD><TD WIDTH=150 BGColor='#00FF00'>Pagename</TD><TD WIDTH=150 BGColor='#00FF00'>Category</TD><TD WIDTH=150
BGColor='#00FF00'>Manufacturer</TD></TR>";
while ($row = mysqli_fetch_array($result))
{
$pagetable .= ('<TR>' . '<TD>' . ($row['id']) . '</TD>' . '<TD>' . ($row['pagename']) . '</TD>' . '<TD>' . ($row['cat']) . '</TD>' . '<TD>' .
($row['manu']) . '</TD>' . '<TD>' . '<form action="?" method="POST">' . '<input type="submit" name="Edit" value="Edit #' . ($row['id']) . '"/>' . '</form>' . '</TD>' . '</TR>');
}
$pagetable .= '</table>';
}
else $error = "You must enter search terms";
include "searchres.html.php";
}
}
?>