help with modifying data script..thanks in advance
Posted: Mon Jan 12, 2004 5:56 pm
I am retrieving data from mysql to a drop down box. The drop down box is populated but how can I select the item and then click the submit button and populated in the text fields in another page in order to modify it. There is two pages, one is update.php which gets the data to a drop down box with a submit button.
The other updatedata.php with text fields populated with data select from the previous drop down box with a update button.
-----------------------------------------------------------------
update.php code below
------------------------------------------------------------------
$query = "select proname from products order by proname";
$result = mysql_query($query) or die(mysql_error());
//create form containing selection list
print "<form action='updatedata.php' method='get'> \n";
print "<select name='proname' size='6'> \n";
while(list($row)=mysql_fetch_array($result))
{
print "<option value='$row'>$row</option> \n";
}
print "</Select> \n";
print "<input type='submit' value='Select product to modify'> </form> \n";// Submit Button
-----------------------------------------------------------------------
updatadata.php code is below
----------------------------------------------------------------------
$query=" SELECT * FROM products WHERE productid='$productid'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$proname=mysql_result($result,$i,"proname");
$price=mysql_result($result,$i,"price");
$prolink=mysql_result($result,$i,"prolink");
$prodate=mysql_result($result,$i,"prodate");
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo "$productid"; ?>">
Product Name: <input type="text" value="ud_first" value="<? echo "$proname"?>"><br>
Price: <input type="text" value="ud_phone" value="<? echo "$price"?>"><br>
Product Link: <input type="text" value="ud_mobile" value="<? echo "$prolink"?>"><br>
Date: <input type="text" value="ud_fax" value="<? echo "$prodate"?>"><br>
<input type="Submit" value="Update">
</form>
++$i;
}
?>
The other updatedata.php with text fields populated with data select from the previous drop down box with a update button.
-----------------------------------------------------------------
update.php code below
------------------------------------------------------------------
$query = "select proname from products order by proname";
$result = mysql_query($query) or die(mysql_error());
//create form containing selection list
print "<form action='updatedata.php' method='get'> \n";
print "<select name='proname' size='6'> \n";
while(list($row)=mysql_fetch_array($result))
{
print "<option value='$row'>$row</option> \n";
}
print "</Select> \n";
print "<input type='submit' value='Select product to modify'> </form> \n";// Submit Button
-----------------------------------------------------------------------
updatadata.php code is below
----------------------------------------------------------------------
$query=" SELECT * FROM products WHERE productid='$productid'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$proname=mysql_result($result,$i,"proname");
$price=mysql_result($result,$i,"price");
$prolink=mysql_result($result,$i,"prolink");
$prodate=mysql_result($result,$i,"prodate");
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo "$productid"; ?>">
Product Name: <input type="text" value="ud_first" value="<? echo "$proname"?>"><br>
Price: <input type="text" value="ud_phone" value="<? echo "$price"?>"><br>
Product Link: <input type="text" value="ud_mobile" value="<? echo "$prolink"?>"><br>
Date: <input type="text" value="ud_fax" value="<? echo "$prodate"?>"><br>
<input type="Submit" value="Update">
</form>
++$i;
}
?>