Solved

Php form: pass more than one value along with select

Posted on 2009-05-07
8
314 Views
Last Modified: 2013-12-12
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
Comment
Question by:Dada44
  • 6
  • 2
8 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24324298
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24324305
hope you submit the form ... other wise you have to change in the select ...

as onchange()
0
 

Author Comment

by:Dada44
ID: 24324376
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24324476
ok fine, then you need to get the ID on the option value
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24324483
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24324495
you need look at here,

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

echo $name;

      echo" </option> ";

Open in new window

0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 24324508
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
 

Author Closing Comment

by:Dada44
ID: 31578951
thanks!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calculate values in an array 18 35
PHP script redirecting to URL not working on AWS EC2 after Elastic IP 12 65
mysql update statement effect only some rows 4 27
PHP warning 4 30
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now