Howdy. I've got a page with your typical INSERT going on, but I have a feeling my dropdown select is interfering with the values being inserted. Basically, there is a dropdown to select a company, then I just want to be able to insert the values into the table. I have one table called cmscompany, and another called cmsdevices. The company table works fine, and I currently have about 300 companies in there. I just can't seem to get the newdevice page to insert any data into the cmsdevices table.
My fields in the cmsdevices table are as follows:
ID (primary)
companyID
device
desc
connect
features
thearticle
This code is based from the article written by Peter Zeidman http://www.intranetjournal.com/articles/200407/ij_07_06_04a.html
Here's my code:
<?php
// --- data entry code
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');
// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){
// Create an instance of DbConnector
$connector = new DbConnector();
// Create an SQL query (MySQL version)
$insertQuery = "INSERT INTO cmsdevices (companyID,device,desc,connect,features,thearticle) VALUES (".
"'".$HTTP_POST_VARS['companyID']."', ".
"'".$HTTP_POST_VARS['device']."', ".
"'".$HTTP_POST_VARS['desc']."', ".
"'".$HTTP_POST_VARS['connect']."', ".
"'".$HTTP_POST_VARS['features']."', ".
"'".$HTTP_POST_VARS['thearticle']."')";
}
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<p><center>Company added to the database</center>';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
exit('<p><center>Sorry, there was an error saving to the database</center>');
}
?>
<form enctype="multipart/form-data" name="Devices" method="POST" action="newdevice.php">
<div class="row"><span class="label">
<?php
$sql="SELECT id,company FROM cmscompany ORDER BY company";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
$company=$row["company"];
$options.="<option value=\"$id\">".$company.'</option>';
}
?>
<select name="companyID" id="companyID" /><option value="0">Choose Company<?=$options?></select></span></div>
<div class="row"><span class="label">Device:</span><span class="formw"><input name="device" type="text" size="35" id="device" /></span></div>
<div class="row"><span class="label">Description:</span><span class="formw"><textarea name="desc" cols="30" rows="6" id="desc"></textarea></span></div>
<div class="row"><span class="label">Connectivity:</span><span class="formw"><input name="connect" type="text" size="35" id="connect" /></span></div>
<div class="row"><span class="label">Features:</span><span class="formw"><textarea name="features" cols="30" rows="6" id="features"></textarea></span></div>
<div class="row"><span class="label">Specifications:</span><span class="formw"><textarea name="thearticle" cols="30" rows="6" id="thearticle"></textarea></span></div>
<div class="row"><span class="formw"><input type="submit" name="action" value="Submit" /> <input type="reset" value="Reset Form" /></span></div>
<div class="spacer"> </div>
</form>
I've gone over my code for over a week now and I just can't get this to work. It's the very last step I need to do to finish this project, and I'm just stuck. Any advice, help, or even just a comment would really help me out. Thank you all in advance!
Cheers,
Rob