Jump to content

Problems with form uploading to MySQL db


clint6998

Recommended Posts

Hello from the newbie!  I have a form that I need to post the data to my MySQL db and it is not working.  It says that it uploaded it, but it doesn't upload the data. Strange thing is that when I go to re-enter the information, it says that the serial number is already in the system.

 

Here is the php process:

<?php
if($_POST['doSubmit'] == 'Add')
{
$rs_dup = mysql_query("select count(*) as total from firearms where serialNumber='$post[serialNumber]'") or die(mysql_error());
list($dups) = mysql_fetch_row($rs_dup);

if($dups > 0) {
	die("That Serial Number already exists in the system.");
	}

mysql_query("INSERT INTO `firearms` (`manufacturer`,`model`,`serialNumber`,`caliber`,`type`,`receiptDate`)
			 VALUES ('$post[manufacturer]','$post[model]','$post[serialNumber]','$post[caliber]','$post[type]',now())
			 ") or die(mysql_error()); 
			 
echo "<div class=\"msg\">New Firearm Added....done.</div>";			 
}
?>

Here is the form:

<p><?php 
if(!empty($msg)) {
echo $msg[0];
} ?></p>
<table width="100%" border="0" cellpadding="5" cellspacing="2" class="myaccount">
  <tr>
    <td width="50%" style="text-align:right"><form name="addNew" id="addNew" method="post" action="new.php">Name of Manufacturer and/or Importer: </td>
    <td width="50%" style="text-align:left"><input name="manufacturer" type="text" id="manufacturer"></td>
  </tr>
  <tr>
    <td style="text-align:right">Model of Firearm: </td>
    <td style="text-align:left"><input name="model" type="text" id="model" class="required"></td>
  </tr>
  <tr>
    <td style="text-align:right">Firearm Serial Number: </td>
    <td style="text-align:left"><input name="serialNumber" type="text" id="serialNumber" class="required"></td>
  </tr>
  <tr>
    <td style="text-align:right">Caliber or Gauge of Firearm: </td>
    <td style="text-align:left"><input name="caliber" type="text" id="caliber" class="required"></td>
  </tr>
  <tr>
    <td style="text-align:right">Type of Firearm (pistol, revolver, shotgun, rifle,etc.): </td>
    <td style="text-align:left"><input name="type" type="text" id="type" class="required"></td>
  </tr>
  <tr>
    <td colspan="2" style="text-align:center"><input name="doSubmit" type="submit" id="doSubmit" value="Add"></form></td>
  </tr>        
</table>

Here is the db structure:

CREATE TABLE IF NOT EXISTS `firearms` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `manufacturer` varchar(200) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  `model` varchar(200) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  `serialNumber` varchar(200) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  `caliber` varchar(200) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  `type` varchar(200) COLLATE latin1_general_ci NOT NULL DEFAULT '',
  `receiptDate` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`id`),
  UNIQUE KEY `serialNumber` (`serialNumber`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

 

Attached is an image of what whose up when the form is processed. It is making an entry, but only populates the 'id' and 'date' fields.

 

Any help would be greatly appreciated!!!

 

Thanks,

 

CLint

post-146385-0-41774100-1365518976_thumb.jpg

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.