Pass variable from option to Insert into query

I am having trouble passing the variables from the option box.  The option boxes are populated from tables in a MySQL database.  All other variables are inserting correctly (line 73) except for the 3 option boxes (lines 101, 123, and 169).  Thanks for your help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http: //www. w3. org/TR/xhtml1/DTD/xhtml1-strict. dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>TCV Path Manual Entry</title>
<style type="text/css">
			style type="text/css">
			body {
				background-color: #FFFFFF;
				margin-left: 10%;
				margin-right: 10%;
				border: 2px solid gray;
				padding: 20px 20px 20px 20px;
				font-family: Verdana, Helvetica, Arial, sans-serif;
				}
			table {
				margin-left: 20px;
				margin-right: 20px;
				border: thin solid white;
				caption-side: top;
				background-color: #E6E6FA
				}
			td, th {
                                font-weight: normal; 
                                font-size: 8pt; 
                                color: #000000; 
                                font-family: verdana, arial, helvetica, sans-serif;
                                text-decoration: none;
                                align="center"
				border: 2px solid white;
				padding: 5px;
				text-align: left;
				}
			caption {
				padding-top: 8px;
				}
			#prop_insp_form{
				background-color: #A3C2FF;
                                align="center";
				}
                        #nav{
				align: center;
				}
		</style>
</head>
<body>
<h3>Manual Job Entry</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="nav">
<ul id="headerNav">
<li><a href="index.php" title="index">Home</a></li>
<li><a href="pending.php" title="Pending">Pending</a></li>
<li class="headerRight"><a href="/logout" title="Logout">Logout</a></li>
</ul>
</div>

<?php

 
 require_once('connvars.php');
 $dbc=mysqli_connect(db_host,db_user,db_password,db_name)or die('Error connecting to MySQL server.');
    
  $tc_number=$_POST['tc_number'];
  $loan_number=$_POST['loan_number'];
  $prop_city=$_POST['prop_city'];
  $prop_addr_1=$_POST['prop_addr_1'];
  $prop_zip=$_POST['prop_zip'];
  $prop_county=$_POST['prop_county'];
  $prin_id=$_POST['principal_id'];
  $prod_id=$_POST['product_id'];
  $state_id=$_POST['prop_state'];

//upload new record to job
if((!empty($tc_number))||(!empty($prop_addr_1))){
  $query="INSERT INTO job (principal_id,product_id,prop_state,tc_number,loan_number,prop_city,prop_addr_1,prop_zip,prop_county)
  VALUES ('$prin_id','$prod_id','$state_id','$tc_number','$loan_number','$prop_city','$prop_addr_1','$prop_zip','$prop_county')";
  $result=mysqli_query($dbc,$query) or die($query.mysql_error('query error'));         
  mysqli_close($dbc);
}


  $tc_number=$_POST['tc_number'];
  $loan_number=$_POST['loan_number'];
  $prop_city=$_POST['prop_city'];
  $prop_addr_1=$_POST['prop_addr_1'];
  $prop_zip=$_POST['prop_zip'];
  $prop_county=$_POST['prop_county'];

   ?>

<div id="entry">
<table>
	<tr>
		<th>Client Name</th>
			<td>
<?php
 
 require_once('connvars.php');

 //drop down for principal 
 
 $dbc=mysqli_connect(db_host,db_user,db_password,db_name)or die('Error connecting to MySQL server.');
 $ddprincipal="select principal_id, principal_name from principal order by principal_name ASC";
 $ddprinresult=mysqli_query($dbc,$ddprincipal);
   echo "<select name=\"$strNameOrdinal\">\n";
   echo "<option value=\"NULL\">Select Client</option>\n";
  while($row = mysqli_fetch_array($ddprinresult)){
     $principal_id = $row['principal_id'];
     $principal_name = $row['principal_name'];
   echo "<option value=\"$principal_id\">$principal_name</option>\n";
   }
  echo"</select>\n";
   ?>
   </td>
   </tr>
   <tr>
      <th>Product</th>
       <td>
<?php
 
 require_once('connvars.php');

 //drop down for product
 echo "</select>\n";$ddproduct="select product_id, product_name from products order by product_name ASC";
 $ddprodresult=mysqli_query($dbc,$ddproduct);
   echo "<select name=\"$strNameOrdinal\">\n";
   echo "<option value=\"NULL\">Select Product</option>\n";
   while($row = mysqli_fetch_array($ddprodresult)) {
      $product_id = $row["product_id"];
      $product_name = $row["product_name"];
      echo "<option value=\"$product_id\">$product_name</option>\n";
   }
   echo "</select>\n";
 
   ?>
    </td>
    </tr.
    <tr>
      <th>TC Number</th>
        <td>
        <input name="tc_number" type="text" />
        </td>
    </tr>   
    <tr>
      <th>Loan Number</th>
        <td>
        <input name="loan_number" type="text" />
        </td>
    </tr>
<tr>
      <th>Property Address</th>
        <td>
        <input name="prop_addr_1" type="text" />
        </td>
    </tr>   
    <tr>
      <th>Property City</th>
        <td>
        <input name="prop_city" type="text" />
        </td>
    </tr>
    <tr>
      <th>Property State</th>
        <td>
<?php
          require_once('connvars.php');
 $dbc=mysqli_connect(db_host,db_user,db_password,db_name)or die('Error connecting to MySQL server.');
 
//drop down for state
 $ddstate="select state_id, state_name from state order by state_name ASC";
 $ddstateresult=mysqli_query($dbc,$ddstate);
   echo "<select name=\"$strNameOrdinal\">\n";
   echo "<option value=\"NULL\">Select Property State</option>\n";
   while($row = mysqli_fetch_array($ddstateresult)) {
      $state_initial = $row["state_initial"];
      $state_name = $row["state_name"];
      echo "<option value=\"$state_initial\">$state_name</option>\n";
   }
   echo "</select>\n";
?>
        </td>
    </tr>   
    <tr>
      <th>Property Zip</th>
        <td>
        <input name="prop_zip" type="text" />
        </td>
    </tr>
<tr>
      <th>Property County</th>
        <td>
        <input name="prop_county" type="text" />
        </td>
     </tr>  
 <tr>
      <th>Agent Name</th>
        <td>
        <input name="agent_name" type="text" />
        </td>
    </tr>
 </table>

<input class="headerSubmit" id="go" name="go" value="Submit" type="submit" />
</div>
</form> 
</body> 
</html>

Open in new window

rcowen00Asked:
Who is Participating?
 
rjdownConnect With a Mentor Commented:
echo "<select name=\"$strNameOrdinal\">\n";

You need to change these lines to

echo "<select name=\"principal_id\">\n"; (line 105)
echo "<select name=\"product_id\">\n"; (line 126)
echo "<select name=\"prop_state\">\n"; (line 172)

OR

before each <select> element, you can change the value of $strNameOrdinal to its correct name, i.e.

$strNameOrdinal = "principal_id"; (before line 105)
$strNameOrdinal = "product_id"; (before line 126)
$strNameOrdinal = "prop_state"; (before line 172)
0
 
amrish80Commented:
hi at ur line 101 u have written
echo "<select name=\"$strNameOrdinal\">\n";

and what is the value for $strNameOrdinal

if not assign it to

$strNameOrdinal="principal";

and then check
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.