I am new to PHP and have been working on a project for some time now. The project requires a page to allow a user to update the rows of a table that have been returned from an SQL query into an HTML table. Right now I have a page with 3 frames: Frame1 is on the left side of the page that has text input boxes that allow a user to at least 1 box to run a search, Frame 2 is the rest of the page to the left where the search results from Frame1's search are returned in an HTML table, Frame3 is the top of the page and irrelevant at this point in time.
As of now when I run a search in Frame1 it returns the results in Frame2's (frontf.php) table with no problems. I have an 'Update' button for each row in the table that when clicked should take the user to a new page (update.php) in Frame2 that will allow them to edit the information and update the row.
My problem is that when I click the update button it reloads Frame2 as the correct file (update.php) however it displays all the rows in the table instead of just the one whose Update button was clicked. Please help me if you can. If you need further explanation please let me know
Code for Frame1 (menu.php):
<!This is from search_test2a.php. 10/16/2010>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Inventory Search</title>
<link rel=stylesheet href="campbell1.css" type="text/css">
</head>
<p><body>
<h3>Search Product Details</h3>
<p>This box allows a user to search by the item(s) description</p>
<form method="post" action="frontf.php?go" target="main">
<label for="name0">Isle1 </label>
<input type="text" name="name0"> <br />
<label for="name1">Column: </label>
<input type="text" name="name1"> <br />
<label for="name2">R: </label>
<input type="text" name="name2"> <br />
<label for="name3">Rows: </label>
<input type="text" name="name3"> <br />
<label for="name4">Quantity: </label>
<input type="text" name="name4"> <br />
<label for="name5">Partnumber: </label>
<input type="text" name="name5"> <br />
<label for="name6">Surplus: </label>
<input type="text" name="name6"> <br />
<label for="name7">Description: </label>
<input type="text" name="name7"> <br />
<label for="name8">Cost: </label>
<input type="text" name="name8"> <br />
<label for="name9">Entryorder: </label>
<input type="text" name="name9"> <br />
<label for="name10">ICRR: </label>
<input type="text" name="name10"> <br />
<label for="name11">IRRC: </label>
<input type="text" name="name11"> <br />
<label for="name12">RowM: </label>
<input type="text" name="name12"> <br />
<input type="submit" name="submit" value="Search Inventory">
</form>
<?php
//******** for now turn on all error reporting:
ini_set('display_errors', 1); // set to 0 for production version
error_reporting(E_ALL);
//*********** let's simplify all those nested if()'s, and use an array instead
//*********** of separate scalar variables:
if (isset($_POST['submit']) && isset($_GET['go'])) {
//connect to the database
$db = mysql_connect("localhost", "root", "") or die('I cannot connect to the database because: ' . mysql_error());
$name = array();
for ($ix = 0; $ix <= 12; $ix++) {
$name[$ix] = (isset($_POST["name$ix"])) ?
mysql_real_escape_string($_POST["name$ix"]) :
false;
}
//********** make sure we got each "name" value from form:
//if (count($name) == count(array_filter($name))) {
//-select the database to use
$mydb = mysql_select_db("cambellsales");
//-query the database table
//********** use array elements:
$sql = "
SELECT Isle, Col, R, Row, Quantity, PartNumber, Surplus, Description, Cost, EntryOrder, ICRR, IRRC, RowM
FROM inventory
WHERE Isle LIKE '%" . $name[0] . "%'
AND Col LIKE '%" . $name[1] . "%'
AND R LIKE '%" . $name[2] . "%'
AND Row LIKE '%" . $name[3] . "%'
AND Quantity LIKE '%" . $name[4] . "%'
AND PartNumber LIKE '%" . $name[5] . "%'
AND Surplus LIKE '%" . $name[6] . "%'
AND Description LIKE '%" . $name[7] . "%'
AND Cost LIKE '%" . $name[8] . "%'
AND EntryOrder LIKE '%" . $name[9] . "%'
AND ICRR LIKE '%" . $name[10] . "%'
AND IRRC LIKE '%" . $name[11] . "%'
AND RowM LIKE '%" . $name[12] . "%'";
//-run the query against the mysql query function
$result = mysql_query($sql);
//********* debug if it failed:
if($result == false) {
user_error(mysql_error()."<br />\n$sql");
}
// Counts the number of rowes that are returned
echo mysql_num_rows($result);
//-create while loop and loop through result set
echo "<table border='1' cellpadding='8' cellspacing='3'
summary=\"Table holds Cambell inventory information\">
<tr>
<th>isle</th>
<th>col</th>
<th>r</th>
<th>rows</th>
<th>quantity</th>
<th>partnumber</th>
<th>surplus</th>
<th>description</th>
<th>cost</th>
<th>entryorder</th>
<th>icrr</th>
<th>irrc</th>
<th>rowm</th>
</tr>";
// Loop through all table rows
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Isle'] . "</td>";
echo "<td>" . $row['Col'] . "</td>";
echo "<td>" . $row['R'] . "</td>";
echo "<td>" . $row['Row'] . "</td>";
echo "<td>" . $row['Quantity'] . "</td>";
echo "<td>" . $row['PartNumber'] . "</td>";
echo "<td>" . $row['Surplus'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" . $row['Cost'] . "</td>";
echo "<td>" . $row['EntryOrder'] . "</td>";
echo "<td>" . $row['ICRR'] . "</td>";
echo "<td>" . $row['IRRC'] . "</td>";
echo "<td>" . $row['RowM'] . "</td>";
echo "</tr>";
}
}
//******** let user know they left something empty:
else {
//echo "<p>ERROR: Not all 'name' fields were entered.</p>";
}
?>
</body>
</html>