Jump to content

Drop Down Menu Retrieve data Help


alanlaw87

Recommended Posts

Hi

 

I have coded a drop down menu with php and i am trying to retrieve the data when a user select a option from the menu and the data is retrieved from the database. So far i have tried and nothing is displaying when i tried to process the php form.

 

Sales.php Page

 

<form action="saleprocess.php" method="GET">

<?php

echo 'Product Model:';

$query="SELECT * FROM products";

/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */

$result = mysql_query ($query);

echo "<select name=product_model value=Select>Product Model</option>";

// printing the list box select command

while($rows=mysql_fetch_array($result)){//Array or records stored in $nt

 

echo "<option name=product_model value='.$rows[product_id].'>$rows[product_model]</option>";

/* Option values are added by looping through the array */

}

echo "</select><br>";

?>

<input type='submit' name='submit' value='Create'></input> <br>

</form>

 

********************************************************************************

Salesprocess.php page

 

<?php

include("connect.php");

 

if(isset($_GET['product_id'])){

 

$product_id = $_GET['product_id'];

 

 

$query = mysql_query("SELECT * FROM products WHERE product_id= $product_id");

 

while($rows = mysql_fetch_assoc($query))

{

echo 'Product Model<br>';

echo $rows['product_id'];

echo $rows['product_model'];

 

 

}

}

?>

 

Muchly appreciated if someone can help me

Link to comment
Share on other sites

You are coding the drop down menu incorrectly. Correct syntax for a drop down is

<select name="menu_name">
   <option value="value1">value1</option>
   <option value="value2">value2</option>
   <option value="value3">value3</option>
   ... etc ...
<select>

Notice you only give the opening <select> tag a name. Each <option></option> has a unique value given to it.

 

You can retrieve the selected value, by using either $_GET['menu_name'] or $_POST['menu_name'] (depending your forms submit method).

 

Corrected code

echo "Product Model: <select name=\"product_model\">";
// printing the list box select command
while($rows = mysql_fetch_array($result)) {//Array or records stored in $nt
echo "<option value=\"{$rows['product_id']}\">{$rows['product_model']}</option>";
/* Option values are added by looping through the array */
}
echo "</select><br />";

 

Please use


or


tags when posting code. It'll make reading your code alot easier

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.