Jump to content

Drop-down Menus not posting into Database, yet rest of form is


Matt Ridge

Recommended Posts

Ok, I have one database three tables.

 

Table 1 is ncmr the main table where everything is to be entered.

 

Table 2 is companies, where all the companies in pull down menu 1 is located.

 

Table 3 is fabricators, where all the people who have had hands on the product are residing.

 

I want the selected choices of table 2 and 3 to be inputed into table 1. I know this has to be possible, but I don't know how.  I thought I wrote the code correctly, but it seems not.

 

Can someone review my code and show me where my mistake is?

 

Here is the page:

 

http://kaboomlabs.com/PDI/post2.php

 

Thanks.

 

    <?php
    
    require_once('connectvars.php');
    		$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
    		or die('Error connecting to MySQL server.');
    ?>
    
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>PDI Non-Conforming Materials Report</title>
    <link rel="stylesheet" type="text/css" href="CSS/postie.css" />
    
    </head>
    
    <body>
    <div id="logo">
    	<img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" />
    </div>
    
    <div id="title">
    	<h3 id="NCMR2">Non-Conforming Materials Report (NCMR)</h3>
    </div>
    <?php
    //Post Data
     if (isset($_POST['submit'])) {
    	$ab = mysqli_real_escape_string($dbc,$_POST['ab']);
    	$date = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime ($_POST['date'])));
    	$part = mysqli_real_escape_string($dbc,$_POST['part']);
    	$rev = mysqli_real_escape_string($dbc,$_POST['rev']);
    	$partdesc = mysqli_real_escape_string($dbc,$_POST['partdesc']);
    	$ncmrqty = mysqli_real_escape_string($dbc,$_POST['ncmrqty']);
    	$comp = mysqli_real_escape_string($dbc,$_POST['comp']);
    	$ncmrid = mysqli_real_escape_string($dbc,$_POST['ncmrid']);
    	$rma = mysqli_real_escape_string($dbc,$_POST['rma']);
    	$jno = mysqli_real_escape_string($dbc,$_POST['jno']);
    	$fdt = mysqli_real_escape_string($dbc,$_POST['fdt']);
    	$cof = mysqli_real_escape_string($dbc,$_POST['cof']);
    	$fab1= mysqli_real_escape_string($dbc,$_POST['fab1']);
    	$fab2= mysqli_real_escape_string($dbc,$_POST['fab2']);
    	$fab3= mysqli_real_escape_string($dbc,$_POST['fab3']);
    	$non= mysqli_real_escape_string($dbc,$_POST['non']);
    	$dis= mysqli_real_escape_string($dbc,$_POST['dis']);
    	$comm= mysqli_real_escape_string($dbc,$_POST['comm']);
    	$caad= mysqli_real_escape_string($dbc,$_POST['caad']);
    	$po= mysqli_real_escape_string($dbc,$_POST['po']);
    	$pod = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['pod'])));
    	$dri = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['dri'])));
    
    	$output_form = 'no';
    	if (empty($ab) || empty($date) || empty($part) || empty($partdesc)){
    
    // We know at least one of the input fields is blank 
    echo '<div id="alert">';
    echo 'Please fill out all of the required NCMR information.<br />';
    	echo '</div>';
    
    }
    	$output_form = 'yes';
    	
    }
    
    //Access the Database
    	if (!empty($ab) && !empty($date) && !empty($pod)) {
    		$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
    		or die('Error connecting to MySQL server.');
    		
    	$query = "INSERT INTO ncmr (ab, date, part, rev, partdesc, ncmrqty, comp, ncmrid, rma, jno, fdt, cof, fab1, fab2, fab3, non, dis, comm, caad, po, pod, dri)
    
    	VALUES ('$ab','$date','$part','$rev','$partdesc','$ncmrqty','$comp','$ncmrid','$rma','$jno','$fdt','$cof','$fab1','$fab2','$fab3','$non','$dis','$comm','$caad','$po','$pod','$dri')";
    	
    	$data = mysqli_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query");
    
    
          // Confirm success with the user
    	echo '<tr><td class="thank">';
    	echo '<p>Thank you for adding the NCRM, the correct person will be informed.</p>';
    	echo '<p><a href="post.php"><< Back to the form</a></p>';
    		$output_form = 'no';
    	echo '</td></tr>';
    
    	mysqli_close($dbc);
    }
      if ($output_form == 'yes') {
    echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
    		echo '<fieldset>';
    		//Part, Rev, Part Description, NCMR Qty
    			echo '<div id="box1">';
    				echo '<div id="ab"><span class="b">Added By:  </span><input type="text" name="ab" value="" /></div>';
    				echo '<div id="date"><span class="b">Date Filed:  </span><input type="text" name="date" value="" /></div>';
    				echo '<div id="part"><span class="b">Part Number:  </span><input type="text" name="part" value="" /></div>';
    				echo '<div id="rev"><span class="b">Part Revision:  </span><input type="text" name="rev" value="" /></div>';
    				echo '<div id="partdesc"><span class="b">Part Description:  </span><textarea name="partdesc" rows="3" cols="22" ></textarea></div>';
    				echo '<div id="ncmrqty"><span class="b">NCMR Qty:  </span><input type="text" name="ncmrqty" value="" /></div>';
    			echo '</div>';
    
    
    //Company, Customer NCMR, Internal RMA, and Job Number
    			echo '<div id="box2">';
    				echo'<div id="comp">';
    					echo '<span class="b">Company:  </span>';
    					$mysqli->select_db('comp');
    					$result = $mysqli->query("SELECT * FROM comp"); 
    					$i = 0;
    				echo "<SELECT name='comp'>\n";
    					while($row = $result->fetch_assoc()) {
    					if ($i == 4) echo '<option value="lines">-----</option>';
    				echo "<option value='{$row['user_id']}'>{$row['name']}</option>\n";
    					$i++;
    					}
    				echo "</select>\n";
    				echo '</div>';
    				
    				echo '<div id="ncmrid"><span class="b">Customer NCMR ID:  </span><input type="text" name="ncmrid" value="" /></div>';
    				echo '<div id="rma"><span class="b">Internal RMA #:  </span><input type="text" name="rma" value="" /></div>';
    				echo '<div id="jno"><span class="b">Job #:  </span><input type="text" name="jno" value="" /></div>';
    			echo '</div>';
    
    
    //Type of Failure and Class of Failure
    			echo '<div id="box3">';
    				echo '<h2>Failure</h2>';
    				echo '<div id="fdt">';
    					echo '<span class="b">Failure Due To:  </span><br />';
    					echo '<select name="fdt">';
    					echo '<option value="none">----None----</option>';
    					echo '<option value="In House">In House</option>';
    					echo '<option value="Third Party">Third Party</option>';
    					echo '</select>';
    					echo '</div>';
    
    				echo'<div id="cof">';
    					echo '<span class="b">Class of Failure:  </span><br />';
    					echo '<select name="cof">';
    					echo '<option value="none">----None----</option>';
    					echo '<option value="Materials">Materials</option>';
    					echo '<option value="Fabrication">Fabrication</option>';
    					echo '<option value="Drawing">Drawing</option>';
    					echo '<option value="Assembly">Assembly</option>';
    					echo '<option value="Testing">Testing</option>';
    					echo '<option value="Electrical">Electrical</option>';
    					echo '<option value="Programming">Programming</option>';
    					echo '<option value="Machining">Machining</option>';
    					echo '<option value="Inspection">Inspection</option>';
    					echo '<option value="Purchasing">Purchasing</option>';
    					echo '<option value="Administrator">Administrator</option>';
    					echo '</select>';
    				echo '</div>';
    			echo '</div>';
    	
    	//Fabricators
    			echo '<div id="box4">';
    				echo '<h2>Fabricators</h2>';
    					echo'<div id="fab1">';
    						$mysqli->select_db('user');
    						$result = $mysqli->query("SELECT * FROM user"); 
    							echo "<SELECT name='fab1'>\n";
    								while($row = $result->fetch_assoc()) { 
    							echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";}
    						echo "</select>\n";
    					echo '</div>';
    
    					echo'<div id="fab2">';
    						$mysqli->select_db('user');
    						$result = $mysqli->query("SELECT * FROM user"); 
    							echo "<SELECT name='fab2'>\n";
    								while($row = $result->fetch_assoc()) { 
    							echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";}
    						echo "</select>\n";
    					echo '</div>';
    
    					echo'<div id="fab3">';
    						$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    						$mysqli->select_db('user');
    						$result = $mysqli->query("SELECT * FROM user"); 
    							echo "<SELECT name='fab3'>\n";
    								while($row = $result->fetch_assoc()) { 
    							echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";}
    							echo "</select>\n";
    					echo '</div>';
    			echo '</div>';
    
    			 //Nonconformity, Disposition, Comments and Comments & Additional Details
                echo '<div id="box5">';
    					echo '<div id="non"><span class="b">Nonconformity:  </span><br /><textarea name="non" rows="3" cols="110" ></textarea><br /></div>';
    					echo '<div id="dis"><span class="b">Disposition:  </span><br /><textarea name="dis" rows="3" cols="110" ></textarea></div>';
    					echo '<div id="comm"><span class="b">Comments:  </span><br /><textarea name="comm" rows="3" cols="110" ></textarea></div>';
    					echo '<div id="caad"><span class="b">Comments and/or Additional Details:  </span><br /><textarea name="caad" rows="3" cols="110" ></textarea></div>';
    			//PO, PO Date, and Date Recieved
                echo '<div id="podr">';
    					echo '<div id="po"><span class="b">PO:  </span><input type="text" name="po"  size="7" value="" /></div>';
    					echo '<div id="pod"><span class="b">PO Date:  </span><input type="text" name="pod"  size="7" value="" /></div>';
    					echo '<div id="dri"><span class="b">Date Received:  </span><input type="text" name="dri"  size="7" value=""';
    			echo '</div>';
    					echo '<div id="button"><input type="submit" value="Submit NCMR" name="submit" /></div>';
    			echo '</div>';
    	echo '</fieldset>';
    echo '</form>';
    	}
    
    
    
    
    ?>
    </body>
    </html>

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.