[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Php form: pass more than one value along with select

Hi all,

I have the code below, it fills a select element in a form with information from a mysql table.

It will be filled with the name of the products stored in the table products, but I would also like to get in process.php  the id of the selected product

How can I do that?? I've tried with a hidden field but I don't know where to place it. If I put it inside of the select element it breaks.

Thanks in advance!!
echo"<form action='process.php' method='POST' id='process'>
<select name='product_sel' >";
$query= "SELECT * FROM products";
$result = mysql_query($query);
      while ($row = mysql_fetch_assoc($result)) {
      echo"<option>";
      $name = $row['name'];
      $id = $row['p_id'];
      echo $name;
      echo"
      </option> ";
            }
echo"</select>
</form>";

Open in new window

0
Dada44
Asked:
Dada44
  • 6
  • 2
1 Solution
 
Loganathan NatarajanLAMP DeveloperCommented:
when you post, i mean on the process page,

you can see the posted values from select

echo $_POST['product_sel'];

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
hope you submit the form ... other wise you have to change in the select ...

as onchange()
0
 
Dada44Author Commented:
logudotcom thanks a ton for answering.

If I do  $_POST['product_sel']; I get the name of the product which is great, but I also need the id of the product.
And yes, I have a submit button.

Thanks again!

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Loganathan NatarajanLAMP DeveloperCommented:
ok fine, then you need to get the ID on the option value
0
 
Loganathan NatarajanLAMP DeveloperCommented:
try this,

<select name='product_sel' >";
$query= "SELECT * FROM products";
$result = mysql_query($query);
      while ($row = mysql_fetch_assoc($result)) {
 $name = $row['name'];
      $id = $row['p_id'];     
 echo"<option value='".$id."'>";
     
      echo $name;
      echo" </option> ";
            }
echo"</select>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
you need look at here,

echo"<option value='".$id."'>";
echo $name;
      echo" </option> ";

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
This may be fine,

echo"<form action='process.php' method='POST' id='process'>
<select name='product_sel' >";
$query= "SELECT * FROM products";
$result = mysql_query($query);
      while ($row = mysql_fetch_assoc($result)) {
      $name = $row['name'];
      $id = $row['p_id'];	  
	  echo"<option value='".$id."'>";     
      echo $name;
      echo"</option> ";
       }
echo"</select></form>";
?>

Open in new window

0
 
Dada44Author Commented:
thanks!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now