[thelist] php mysql form problem

kris burford kris at midtempo.net
Thu Aug 29 05:47:01 CDT 2002


hi all,

i've a client with a large list of products (some 300+) that he updates the
price of once every 6-12 months. he's wanting me to create a form where he
can change all the prices, then submit the data (rather than submit each
price change individually) and i'm having difficulty with the mass change...

the fields i've got to play with are product_id, product_name,
product_price and i realise that it should be simple, i just can't see how
i can attribute each item's price with the product id in the form. below is
as far as i've managed...

	$conn = db_connect();
	$sql = "select product_name, product_id, product_price from cs_test order
by product_name";
	$result = mysql_query($sql, $conn) or die ('Couldn\'t select products from
the database');
	$rows = mysql_num_rows($result);
	$product = mysql_fetch_array($result);
	echo "<form action=\"" . $PHP_SELF . "\" method=\"get\" >";
	echo "\n<table cellspacing=\"5\" cellpadding=\"0\">";
	for ($i=0; $i<$rows; $i++) {
		echo "<tr><td>" . stripslashes($product['product_name'][$i]) . "</td><td>";
		echo "<input size=\"20\" name=\"product_price\" value=\"" .
$product['product_price'][$i] . "\" />";
		echo "</td></tr>";
	}
	echo "<tr><td><input type=\"submit\" value=\"Change\" name=\"task\"
class=\"button\" /></td>";
	echo "</tr></table>";
	echo "</form>";


	$conn = db_connect();
		for ($i=0; $i<$rows; $i++) {
	$sql = "update cs_test set product_price = '$product_price' where
?????????????
	$update = mysql_query($sql, $conn) or die ('Couldn\'t update the product
price in the database');
	}

tia

kris



More information about the thelist mailing list