I got this code to work, mostly. I have an issue in where it is posting the comp_id instead of the name, which is the company.
I can’t figure out why. Can someone here look at this code and tell me where the error is?
The table is comp, the fields are comp_id and name.
The test page is: http://kaboomlabs.com/PDI/test4.php
I know I’m missing something but I’ve been staring at this code for too long and I don’t see the obvious mistakes any more. Thanks.
<?php
require_once('connectvars.php');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
or die('Error connecting to MySQL .');
if (isset($_POST['submit'])) {
$comp = mysqli_real_escape_string($dbc,$_POST['comp']);
}
//Access the Database
if (!empty($comp)) {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
or die('Error connecting to MySQL server.');
$query = "INSERT INTO ncmr (comp) VALUES ('$comp')";
$data = mysqli_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query");
mysqli_close($dbc);
}
echo "<form method='post'>";
echo '<fieldset>';
echo'<div id="comp">';
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$mysqli->select_db('comp');
echo '<span class="b">Company: </span>';
$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['name']}'>{$row['name']} </option>\n";
$i++;}
echo "</select>\n";
echo '</div>';
echo '<div id="button"><input type="submit" value="Submit NCMR" name="submit" /></div>';
echo '</fieldset>';
echo '</form>';
?>
I solved this issue, the people here helped, and pointed me in the right direction. The problem was that not one person gave the correct answer, but multiple people gave part of the complete answer.
Here is the script in it’s entirety.