retrieving data from a drop down box for modifying

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
gilbertwang
Forum Commoner
Posts: 32
Joined: Sun Jun 30, 2002 11:08 pm
Location: Calgary

retrieving data from a drop down box for modifying

Post by gilbertwang »

I am doing this script for admin purpose:
I am retrieving data from mysql to a drop down box. The drop down box is populated with product name.

My problem is how can I select the product name and display the details (productname, details, price) on the next page to a text box for update purposes.

There are 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.

Can you guys help me to check my code and if there's a tutorial regarding this feature, please recommend to me. Thank you-----------------------------------------------------------------

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 proname='$proname'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$proname=mysql_result($result,$i,"proname");
$details=mysql_result($result,$i,"details");
$price=mysql_result($result,$i,"price");



<form action="updated.php" method="post">
Product Name: <input type="text" value="pron" value="<? echo "$proname"?>"><br>
Details: <input type="text" value="pdetails" value="<? echo "$details"?>"><br>
Product Price: <input type="text" value="pprice" value="<? echo "$price"?>"><br>
<input type="Submit" value="Update">
</form>


++$i;
}


?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

#1: Whats wrong with it? Errors? Not working correctly? Seems OK to me, although there are a few minor errors.

#2: For your form, you are using the method GET, I would highly recommend using POST.

#3: On your second page (updatedata.php) you can't use the variable $proname (unless Register Globals is on, which should probably be off). You need to use the superglobal array depending on your POST METHOD type. IF you use GET you will need to use the variable $_GET['proname'] and if you use POST then you will need to use the variable $_POST['proname'].
Post Reply