want to pass values from drop down list to other variable...

solunatec
solunatec used Ask the Experts™
on
here is a piece of script: its working ok but I dont know how to pass on the value that is to be selected from the drop down list: as you see the way I have it there is a value passed down but only is the last one..not the one clicked....so I wish to be able to select the click/selected item from the list and pass the value forward to what will be a process.php page...where the values will be inserted into the talbes...
$query="select active_sites_uid, site_address, site_city, site_state, site_zip   from
 	acitve_sites_table where account_id = $account_uid ";
  
  $result = $db->query($query); 
 echo '<select name="opened work orders">'; 
 
$row=mysqli_fetch_assoc($result); 
while($row) 

{   
 echo '<option value="' . $row['account_name'] . '">account: ' . $account_name . '  - active site: ' . $row['site_address'].'  - active uid: ' . $active_sites_uid=$row['active_sites_uid'].'               </option>';
 $row=mysqli_fetch_assoc($result);
}

echo '</select>';


 printf($active_sites_uid);

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can you explain with some more code... more html or something. I think I understand what you have asked but I'm not 100% sure
Hope this attached example helps you
process.php
select.php

Author

Commented:
here is some more code to shed more light on the problem...: I do have a submit button at the bottom of the form but for this select list I want to be able to click on the selected item to pass the value to the form exactly on line 111 ...its quite a hack but its all I know..the code is about lines 81 to 99: by the way although the list box works...I have not figured out why on line 116 I lose the value for $account_uid. when I have line 111 in there...or add
' . $active_sites_uid=$row['active_sites_uid'].'   to the select list...

...its another story but related...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="datetimepicker_css.js"></script>

<title>cobm clients database</title>
<style type="text/css">
body {background-color:#b0c4de}
body {color:darkblue}
h1 {color:darkblue}
hi {font-family:Arial}
h1 {font-size:16px}
h2 {color:darkblue}
h2 {font-family:Arial}
p{font-family:Arial}
p.alt {background-color:#EAF2D3}
p{font-size:12px}
p {font-size:14px}
p.diff {background-color:#b0c4de}
br{font-family:Arial}
</style>
</head>
<body>

<h2>cobm clients database</h2>
<?php
  // create short variable names
  $searchtype=$_POST['searchtype'];
  $searchterm=trim($_POST['searchterm']);

  if (!$searchtype || !$searchterm) {
     echo 'You have not entered search details.  Please go back and try again.';
     exit;
  }

 if (!get_magic_quotes_gpc()){
  	
   $searchtype = addslashes($searchtype);
   $searchterm = addslashes($searchterm);
  }

  @ $db = new mysqli('xxxxxxx', 'xxxxxx', 'xxxxxx','xxxxxxxxx');

  if (mysqli_connect_errno()) {
     echo 'Error: Could not connect to database.  Please try again later.';
     exit;
  }


  
  
$query2= "SELECT * from accounts_table
where ".$searchtype." like '%".$searchterm."%'";

  $result2 = $db->query($query2);

  $num_results2 = $result2->num_rows;

  echo "<p>Number of clients found: ".$num_results2."</p>";

  for ($i=0; $i <$num_results2; $i++) {
     $row = $result2->fetch_assoc();
     echo "<p class=alt /> company name:<strong>" ;
     echo htmlspecialchars(stripslashes($row['account_name']));
     echo "</strong>;
      <br  />address: ";
     echo stripslashes($row['physical_address']);
     echo "<br  />city: ";
     echo stripslashes($row['city']);
     echo "<br />state: ";
     echo stripslashes($row['state_prov']);
     echo "</strong><br />zip: ";
     echo stripslashes($row['zip']);
     echo "<br />account_uid: ";
     echo stripslashes($row['account_uid']);
     echo "</p>"; 
  }; 

 
 $account_uid=($row['account_uid']);
 $account_name=($row['account_name']);


 $query="select active_sites_uid, site_address, site_city, site_state, site_zip   from
 	acitve_sites_table where account_id = $account_uid ";
  
  $result = $db->query($query); 
 echo '<select name="opened work orders">'; 
 
$row=mysqli_fetch_assoc($result); 
while($row) 

{   
 echo '<option value="' . $row['account_name'] . '">account: ' . $account_name . '  - active site: ' . $row['site_address'].'  - active uid: ' . $active_sites_uid=$row['active_sites_uid'].'               </option>';
 $row=mysqli_fetch_assoc($result);
}

echo '</select>';


 $result->free;
 $db->close(); 
 
?>

<form action="resultswo.php" method="post">
 <br />
 <input name="account_uid" type="hidden" value="<? echo $account_uid=($row['account_uid']); ?>">
        <br />
     <input name="todays_date" type="hidden" value="<?php echo date("d/m/y : H:i:s", time()) ?>;" >
          <br />
     Choose job type:
    <br />
    <select name="job_code">
      <option value="1">buff floor
      <option value="2">post construction
      <option value="3">strip and wax
      <option value="4">scrub and wax
      <option value="5">window cleaning
      <option value="6">general clean
      <option value="7">remove garbage
      <option value="8">disinfect area
      <option value="9">scrub only
      <option value="10">check comments
      <option value="11">client direction
    </select>
     <br />
     billable or non:<br />
    <select name="billable_or_non">
      <option value="1">billable
      <option value="2">non billable
      <option value="3">n/a
    </select>
    <br /> 
    job date:<br />
         <input id="demo1" type="text" size="25" name="work_date"> 
<a href="javascript:NewCssCal('demo1')"> 
<img src="images/cal.gif" width="16" height="16" alt="Pick a date"></a>
<br />
	job time:<br />
hours:
    <select name="hours">
      <option value="1">1am
      <option value="2">2am
      <option value="3">3am
      <option value="4">4am
      <option value="5">5am
      <option value="6">6am
      <option value="7">7am
      <option value="8">8am
      <option value="9">9am
      <option value="10">10am
      <option value="11">11am
      <option value="12">12am
      <option value="13">1pm
      <option value="14">2pm
      <option value="15">3pm
      <option value="16">4pm
      <option value="17">5pm
      <option value="18">6pm
      <option value="19">7pm
      <option value="20">8pm
      <option value="21">9pm
      <option value="22">10pm
      <option value="23">11pm
      <option value="24">12pm
      </select>
minutes:
    <select name="half_hours">
      <option value=":00">00
      <option value=":15">15
      <option value=":30">30
      <option value=":45">45
    </select>
   <br />
    projected hours:<br />
    <select name="projected_hours">
      <option value="1">1
      <option value="2">2
      <option value="3">3
      <option value="4">4
      <option value="5">5
      <option value="6">6
      <option value="7">7
      <option value="8">8
      <option value="9">9
      <option value="10">10
      <option value="15">15
      <option value="20">20
      <option value="25">25
      <option value="30">30
      <option value="35">35
      <option value="40">40
      <option value="50">50
      <option value="60">60
      <option value="70">70
      <option value="80">80
      <option value="90">90
      <option value="100">100
      <option value="150">150
      <option value="200">200
    </select>
    <br />
    payout:<br />
      <input type="text" name="payout" maxlength="30" size="30">
	<br />
    <br />estimated supply cost:<br />
    <select name="est_supply_cost">
      <option value="10">10
      <option value="20">20
      <option value="30">n/a
    </select>
     <br />
       square footage:<br />
    <select name="sqr_footage">
      <option value="1">1
      <option value="2">2
      <option value="3">3
      <option value="4">4
      <option value="5">5
      <option value="6">6
      <option value="7">7
      <option value="8">8
      <option value="9">9
      <option value="10">10
      <option value="15">15
      <option value="20">20
      <option value="25">25
      <option value="30">30
      <option value="35">35
      <option value="40">40
      <option value="50">50
      <option value="60">60
      <option value="70">70
      <option value="80">80
      <option value="90">90
      <option value="100">100
      <option value="150">150
      <option value="200">200
    </select>
       <br />
      surface code:<br />
    <select name="surface_code">
      <option value="1">vct
      <option value="2">wood
      <option value="3">stone
      <option value="4">ceramic
      <option value="5">carpet
      <option value="6">rug
      <option value="7">glass
      <option value="8">stainless steel
      <option value="9">marble
      <option value="10">grout lines
      </select>
      <br />
      comment:<br />
      <input type="text" name="comment" maxlength="50" size="50">   
       <br />
       <input type="submit" name="submit" value="input work order">
       </form>
       </body>
    </html>




processing...***********part
<html>
<head>
  <title>work order report</title>

  
</head>
<body>
<h1>work order report</h1>
<?php



  // create short variable names
  $todays_date=$_POST['todays_date'];
  $active_sites_uid=$_POST['active_sites_uid'];
  $work_order_uid=$_POST['work_order_uid'];
  $account_uid=$_POST['account_uid'];
  $job_code=$_POST['job_code'];
  $billable_or_non=$_POST['billable_or_non'];
  $work_date=$_POST['work_date'];
  $job_time=$_POST['hours'].''.$_POST['half_hours'];
  $projected_hours=$_POST['projected_hours'];
  $payout=$_POST['payout'];
  $est_supply_cost=$_POST['est_supply_cost'];
  $sqr_footage=$_POST['sqr_footage'];
  $surface_code=$_POST['surface_code'];
  $comment=$_POST['comment'];
  
printf($active_sites_uid);

   @ $db = new mysqli('xxxxxxx', 'xxxxxx', 'xxxxx', 'xxxxxxxxx');

  if (mysqli_connect_errno()) {
     echo "Error: Could not connect to database.  Please try again later.";
     exit;
  };

  $query = "insert into wo_stats values
            ('".$todays_date."','".$active_sites_uid."','".$work_order_uid."','".$account_uid."','".$billable_or_non."','".$work_date."','".$job_time."','".$payout."','".$est_supply_cost."','".$comment."')" ; 


  
$result = $db->query($query);

$id=$db->insert_id;

printf ("New Record has id %d.\n", $id);

if ($result) {
      echo  $db->affected_rows." set of data inserted into wo_stats table.";
      
  } else {
  	  echo "An error has occurred.  The item was not added.";
  }
  
  
$query = "insert into wo_table values
  ('".$id."', '".$job_code."','".$projected_hours."','".$sqr_footage."','".$surface_code."')"; 
$result = $db->query($query);
if ($result) {
      echo  $db->affected_rows." set of data inserted into the wo_table table.";
      
  } else {
  	  echo "An error has occurred.  The item was not added.";
  }
  
  
  
  
  
  

  $db->close();
?>
</body>
</html>

Open in new window

Author

Commented:
just wanted to change scope of question..seemed that hack job was too daunting...in this related piece of code: just wondering why the selected item on the list is always the last and how I can get the select list to actually select the selected item...:any help would be appreciated...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="datetimepicker_css.js"></script>

<title>cobm clients database</title>
<style type="text/css">
body {background-color:#b0c4de}
body {color:darkblue}
h1 {color:darkblue}
hi {font-family:Arial}
h1 {font-size:16px}
h2 {color:darkblue}
h2 {font-family:Arial}
p{font-family:Arial}
p.alt {background-color:#EAF2D3}
p{font-size:12px}
p {font-size:14px}
p.diff {background-color:#b0c4de}
br{font-family:Arial}
</style>
</head>
<body>

<?php
$user="xxxxxxxx";

$host="xxxxx";
$password="xxxxxxxxx";
$database = "xxxxxxxx";
$cxn = mysqli_connect($host,$user, $password, $database)
or die ("couldn’ t connect to server" ) ;


$query="select account_name, site_address, site_city, site_state, work_order_uid
FROM accounts_table AS a, acitve_sites_table AS ac, wo_stats AS w
WHERE a.account_uid = ac.account_id
AND w.active_sites_uid = ac.active_sites_uid"; 



$result = mysqli_query($cxn,$query)
or die ( "Couldn’t execute query." ) ;

/* create form containing selection list */
echo "<form action='opened_work_order.php' method='POST' >
<select name='work_order_uid' >\n";
while ($row = mysqli_fetch_assoc($result) )
{ 
extract($row) ;
//echo "<option value='$account_name' >$account_name \n" ;



echo "<option value=$work_order_uid >$account_name , $site_address, $site_city, $site_state, $work_order_uid \n";
 
}
echo "</select>\n"  ;
echo "<input type='submit'  value='add to opened work order' >
</form>\n";
printf($work_order_uid);

?>
</body>
</html>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial