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

x
?
Solved

Pass HTML select box

Posted on 2009-05-01
3
Medium Priority
?
385 Views
Last Modified: 2013-12-12
This is a very simple answer i believe however i cant seam to find it. I have php page running on my freebsd box which simply runs a mysql select and pulls out all the customer details. see attached code. However i want a select box which is populated from the mysql database. I have done that with the following code.
<select name="group_name">
<?php
$group_select = "
      SELECT DISTINCT
      group_name
      FROM
      customer_accounts
";
$rs = mysql_query($group_select);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"".$row['category_id']."\">".$row['group_name']."\n  ";
}
?>
</select>

however i want the value that i select here to become the $group_name veriable in the php script. How can i achieve this.

With Regards

Purple Oak
<?php
 
// load up the db connection
require_once('connect.php');
 
//connect to the DB
mysql_select_db($database_conn, $conn);
$group_name = 'MS520A';
$query = "
  SELECT
    customer_accounts.nac,
	customer_accounts.salutation,
	customer_accounts.fullname,
	customer_accounts.address_line_1,
	customer_accounts.address_line_2,
	customer_accounts.address_line_3,
	customer_accounts.address_line_4,
	customer_accounts.address_line_5,
    customer_accounts.postcode 
  FROM
    customer_accounts
  WHERE
    customer_accounts.group_name = '". $group_name ."'
";
 
$customeraccounts = mysql_query($query) or die("Bad Query: " . mysql_error());
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>JM Select</title>
</head>
<body>
<h1>Customer Orders</h1>
<?php while ($customer = mysql_fetch_array($customeraccounts, MYSQL_ASSOC)): ?>
  <?php echo $customer['nac'],",",$customer['salutation'],",",$customer['fullname'],",",$customer['address_line_1'],",",$customer['address_line_2'],",",$customer['address_line_3'],",",$customer['address_line_4'],",",$customer['address_line_5'],",",$customer['postcode']?>,<br />
  <?php
    $nac = $customer['nac'];
    $queryorder = "
      SELECT DISTINCT
        order_number,
		total_cost,
		order_date
      FROM
        purchase_history
      WHERE
        nac = '". $nac ."'
	  ORDER BY
	    order_date
      ";
	  $customerorders = mysql_query($queryorder) or die("Bad Query: " . mysql_error());
  ?>
  <?php while ($order = mysql_fetch_array($customerorders, MYSQL_ASSOC)): ?>
    <?php echo $order['order_number'],",",$order['total_cost'],",",$order['order_date']?>,<br />
  <?php endwhile ?>
<?php endwhile ?>
 
</body>
</html>

Open in new window

0
Comment
Question by:purpleoak
3 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24280049
Use sessions
http://uk2.php.net/manual/en/book.session.php

Place the <select> inside a form. When you submit you can use the $_POST['value'] superglogal to get the option.
0
 
LVL 6

Accepted Solution

by:
gxp071 earned 2000 total points
ID: 24280149
How is the form being submitted? Post, Get?  Im assuming the first code is part of a html form that submits via posts/gets to the script you attached in the code box. in which case all you need to do is:

$group_name = $_POST['group_name']; or $_GET['group_name']  if the form is submitting via get...  but if you going to pass that straight into an sql query you should sanatize it to stop sql injection.

Appologies if ive totally miss interperated your question but it a bit hard to figure out what your doing as you sample in the question is not related to the code snippit.

Hope it help Gaz.
0
 
LVL 2

Author Closing Comment

by:purpleoak
ID: 31576889
pointed me the way i needed to go thanks
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses
Course of the Month19 days, 10 hours left to enroll

872 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