loop problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

loop problem

Post by aceconcepts »

I have a problem with a form and it's field which are within a loop.

Please visit the url at the bottom of the page to see for yourself.

Here is my code:

Code: Select all

<?php
include"conn.inc.php";

//SET VARIABLE VALUE OF VARIABLE PASSED THROUGH URL
$type = $_REQUEST['type'];

//GET PRODUCTS BASED ON VARIABLE 'TYPE' PASSED THROUGH THE URL
$view = "SELECT * FROM product WHERE prod_type = '$type'";
$results = mysql_query($view)
	or die(mysql_error());
//NOW DEFINE THE TABLE USED TO HOLD THE QUERY RESULTS
?>
		<html>
		<head>
		<title>Product(s): <?php echo $type; ?></title>
		</head>
		<body>
		<div align="center">
			<table width="760" border="0" cellspacing="0">
				<tr>
					<td width="5"></td>
					<td width="150">
					Name
					</td>
					<td width="145">
					Description
					</td>
					<td align="center" width="60">
					Type
					</td>
					<td align="right" width="60">
					Unit Cost
					</td>
					<td align="right" width="60">
					Unit Price
					</td>
					<td align="center" width="50">
					Stock
					</td>
					<td align="center" width="70">
					Update
					</td>
				</tr>
			</table>
	<form name="form1" method="POST" action="update_product.php?pid=<?php echo $pid; ?>">
			<table width="760" border="0" cellspacing="1">
 <?php 
 
//INITIATE A WHILE LOOP IN ORDER TO EXTRACT EVERY RECORD WHERE THE REC TYPE = $TYPE
while ($row = mysql_fetch_array($results)) {
	extract($row);
$ProdId = $row['product_id'];
//NOW DEFINE THE TABLE CELLS THAT WILL HOLD THE EXTRACTED DATA VARIABLES
echo "<tr>";
echo "<td width=\"5\"></td>";

echo "<td width=\"150\">";
echo "<input type=\"text\" name=\"product_name\" value=" .
	 $prod_name . "\">";
echo "</td>";

echo "<td width=\"145\">";
echo "<input type=\"text\" name=\"product_description\" value=" .
	 $prod_description . "\">";
echo "</td>";

echo "<td width=\"60\">";
echo "<input type=\"text\" size=\"5\" name=\"type\" value=" .
		$prod_type . "\">";
echo "</td>";

echo "<td width=\"60\">";
echo "<input type=\"text\" name=\"cost\" value=" .
		$prod_unit_cost . "\">";
echo "</td>";

echo "<td width=\"60\">";
echo "<input type=\"text\" name=\"price\" value=" .
		$prod_unit_price . "\">";
echo "</td>";

//THIS COLUMN WILL DISPLAY A FORM'S TEXT FIELD EQUAL
//TO THE VALUE OF THE DATABASE FIELD $prod_stock_qty
echo "<td width=\"50\">";
echo "<input type=\"text\" name=\"qty\" value=" .
		$prod_stock_qty . "\">";
echo "</td>";

//THIS COLUMN WILL PROVIDE THE USER WITH A SUBMIT BUTTON
//ENABLING THEM TO UPDATE CHANGES THEY MAKE TO EACH RECORD IN-TURN
echo "<td width=\"70\">";
echo "<input type=\"submit\" name=\"submit\" value=\"Update\">";
echo "</td>";

echo "</tr>";
}
?>
</table>
</form>
</div>
</body>
</html>
Here is the url:
http://chaplin.flump.net/~ace/ace_cart/ ... _login.php

The username is "admin" and the password is "k0106584"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It'd be helpful if you defined what the problem was.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

I posted the url because its easier for you to see the problem than have me try to explain.

Anyhow, when i pass a variable through the url, from one page in order to display a list of records extracted from a mysql db based on the passed variable, the list is extracted perfectly using (extract($row) and then referencing the table fields).

However, when i try to use form fields within the 'while' loop and then set the value of these fields as the table variables it does not display properly. The second field displays html!

Some of the values of the second field in the table are blank, would this pose a problem?

I hope i've explained it clearly.
Post Reply