Jump to content

How to get the value of a php created dropdown list


Darkmatter5

Recommended Posts

Below is the code to the page I have.  If I were to select Texas it'll output this...

state_id:

state_id:

without any id numbers.  What am I doing wrong?  It should output...

state_id: 1

state_id: 1

 

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="library/site_config.css" />
</head>

<body>
<form method="post">
<div align="center" id="addemployee">
<table class="sample" width="800" border="0" align="center">
  <caption class="style20">ADD EMPLOYEE ENTRY</caption>
  <tr>
    <td width="130" class="style22"> </td>
    <td width="150"><div align="center" class="style21">New data for database</div></td>
    <td width="352"><div align="center" class="style21">Description</div></td>
    <td width="300"><div align="center" class="style21">Function status</div></td>
  </tr>
  <tr>
    <td class="style22"><strong>First name:</strong></td>
    <td><input name="first_name" type="text" tabindex="1" /></td>
    <td rowspan="2" class="style23">Enter clients first and last name. If the primary identifier of the client is a company name, also include a person as a contact for the company.</td>
    <td rowspan="11"><div align="center" class="style23" id="results">
    	<?php
		if(isset($_POST['addemployee'])) {
			include 'library/dbconfig.php';
			include 'library/opendb.php';

			$first_name=$_POST['first_name'];
			$last_name=$_POST['last_name'];
			$address=$_POST['address'];
			$city=$_POST['city'];
			$state_id=$_POST['state'];
			$zip_code=$_POST['zip_code'];
			$home_phone=$_POST['home_phone'];
			$cell_phone=$_POST['cell_phone'];
			if ($_POST['active_employee']==1) {
				$active_employee="Yes";
			} else $active_employee="No";
			if ($_POST['lic_rpls']==1) {
				$lic_rpls="Yes";
			} else $lic_rpls="No";
			if ($_POST['lic_pe']==1) {
				$lic_ps="Yes";
			} else $lic_pe="No";
			//put new client data from form into the clients table
			foreach (array('first_name', 'last_name', 'address', 'city',  'state_id', 'zip_code', 'home_phone', 'cell_phone', 'active_employee', 'lic_rpls', 'lic_pe') as $field) {
			if ($_POST[$field]) {
				$field_name[]=$field;
				$field_value[]="'{$_POST[$field]}'";
			}
		}
//			$fields=join(", ", $field_name);
//			$values=join(", ", $field_value);
//			$insertdata="INSERT INTO byrnjobdb.employees ($fields) VALUES ($values)";
//			mysql_query($insertdata) or die('Error, insert query failed');
//			echo $FirstName. " " .$LastName. " ADDED to employees table...";
/*			foreach ($field_name as $out) {
			echo $out. "<br>";
		}*/
		echo "state_id: " .$state_id. "<br>";
		echo "state_id: " .$_POST['state_id'];

		include 'library/closedb.php';
	}
	?>
    </div></td>
  </tr>
  <tr>
    <td class="style22"><strong>Last name:</strong></td>
    <td><input name="last_name" type="text" tabindex="2" /></td>
  </tr>
  <tr>
    <td class="style22"><strong>Address:</strong></td>
    <td><input name="address" type="text" tabindex="3" /></td>
    <td class="style23"> </td>
  </tr>
  <tr>
    <td class="style22"><strong>City:</strong></td>
    <td><input name="city" type="text" tabindex="4" /></td>
    <td class="style23"> </td>
  </tr>
  <tr>
    <td class="style22"><strong>State:</strong></td>
    <td>
	<?php
        	include 'library/dbconfig.php';
		include 'library/opendb.php';

		$query="SELECT state_id, state, state_abbrev
				FROM byrnjobdb.states
				ORDER BY state ASC";
		$result=mysql_query($query);
		echo "<select id='state' method='get' tabindex='5'>";
		echo "<option>---Select---</option>";
		while ($row=mysql_fetch_array($result)) {
			$r1=$row['state_id'];
			$r2=$row['state']. ", " .$row['state_abbrev'];
			echo "<option value='$r1'>$r2</option>";
		}
		echo "</select>";

		include 'library/closedb.php';
	?>
    </td>
    <td class="style23"> </td>
  </tr>
    <tr>
    <td class="style22"><strong>Zip Code:</strong></td>
    <td><input name="zip_code" type="text" tabindex="6" /></td>
    <td class="style23"> </td>
  </tr>
  <tr>
    <td class="style22"><strong>Home phone:</strong></td>
    <td><input name="home_phone" type="text" tabindex="7" /></td>
    <td class="style23"> </td>
  </tr>
  <tr>
    <td class="style22"><strong>Cell phone:</strong></td>
    <td><input name="cell_phone" type="text" tabindex="8" /></td>
    <td class="style23"> </td>
  </tr>
  <tr>
    <td class="style22"><strong>Is employee active?</strong></td>
    <td><input type="checkbox" name="active_employee" value="1" tabindex="9" />Yes</td>
    <td class="style23">Check yes or no depending on if the employee is a current/active employee.</td>
  </tr>
  <tr>
    <td class="style22"><strong>Is employee an RPLS?</strong></td>
    <td><label><input type="checkbox" name="lic_rpls" value="1" tabindex="10" />Yes</label></td>
    <td class="style23">Is this employee an RPLS (Registered Public Land Surveyor)?</td>
  </tr>
  <tr>
    <td class="style22"><strong>Is employee a PE?</strong></td>
    <td><label><input type="checkbox" name="lic_pe" value="1" tabindex="11" />Yes</label></td>
    <td class="style23">Is this employee a P.E. (Public Engineer)?</td>
  </tr>
  <tr>
    <td colspan="3" class="style22"><div align="center">
      <input name="addemployee" type="submit" id="addemployee" value="Submit new employee entry" tabindex="12" />
    </div></td>
    <td> </td>
  </tr>
</table></div>
</form>
</body>
</html>

 

The states table is fully populated.  Example below...

+------------+-----------+----------+

| state_id | state| state_abbrev

+------------+-----------+----------+

| 1 | Texas | TX

| 2 | Arkansas | AR

| 3 | California | CA

+------------+-----------+----------+

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.