Trouble with Insert from php form
Posted: Mon May 12, 2008 11:03 pm
I have a php form that works, except for one field. Here is what I have:
HTML Form:
<html>
<head>
</head>
<body bgcolor="#C0C0C0">
<img src="SNAlogo1.jpg" width="74" height="74">
<center>
<form method="post" action="batch2.php">
<input type="hidden" name="BatchNum" value="null">
<table>
<tr><td align="left">Model Type:</td>
<td><input type="text" name="ModelType"size="15"></td>
</tr>
<tr><td align="left">Type of Repair:</td>
<td><input type="text" name="CardType" size="10"></td>
</tr>
<tr><td align="left">OEM SKU:</td>
<td><input type="text" name="OEMSku" size="7"></td>
</tr>
<tr><td align="left">OEM Model Number:</td>
<td><input type="text" name="OEMModel" size="20"></td>
</tr>
<tr><td align="left">Quantity in the Order:</td>
<td><input type="text" name="Qty" size="11"></td>
</tr>
<tr><td align="left">Receiving Date:</td>
<td><input type="text" name="RecvDate" size="20"></td>
</tr>
<tr><td colspan="2">
<p align="center">
<input type="submit" value="Create Batch">
</td>
</tr>
</table>
</form>
</center>
</html>
and the php script is:
<?php
$con = mysql_connect("localhost","root","c0d3r3d!");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("snalogdata", $con);$sql="INSERT INTO snabatch (ModelType, CardType, OEMModel, OEMSku, Qty, RecvDate)
VALUES
('$_POST[ModelType]','$_POST[CardType]','$_POST[OEMModel]','$_POST[OEMSku]','$_POST[Qty]','$_POST[RecvDate]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Batch Number $BatchNum Created";mysql_close($con)
?>
The only issue is that the QTY field is not inserting the data (I get a zero value). IN the database it is an integer field. From looking at the field setup in the table it is set for NOT NULL and you cannot get rid of the DEfault value of 0 (the not null). Could this be the problem?
Thanks,
Texman
HTML Form:
<html>
<head>
</head>
<body bgcolor="#C0C0C0">
<img src="SNAlogo1.jpg" width="74" height="74">
<center>
<form method="post" action="batch2.php">
<input type="hidden" name="BatchNum" value="null">
<table>
<tr><td align="left">Model Type:</td>
<td><input type="text" name="ModelType"size="15"></td>
</tr>
<tr><td align="left">Type of Repair:</td>
<td><input type="text" name="CardType" size="10"></td>
</tr>
<tr><td align="left">OEM SKU:</td>
<td><input type="text" name="OEMSku" size="7"></td>
</tr>
<tr><td align="left">OEM Model Number:</td>
<td><input type="text" name="OEMModel" size="20"></td>
</tr>
<tr><td align="left">Quantity in the Order:</td>
<td><input type="text" name="Qty" size="11"></td>
</tr>
<tr><td align="left">Receiving Date:</td>
<td><input type="text" name="RecvDate" size="20"></td>
</tr>
<tr><td colspan="2">
<p align="center">
<input type="submit" value="Create Batch">
</td>
</tr>
</table>
</form>
</center>
</html>
and the php script is:
<?php
$con = mysql_connect("localhost","root","c0d3r3d!");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("snalogdata", $con);$sql="INSERT INTO snabatch (ModelType, CardType, OEMModel, OEMSku, Qty, RecvDate)
VALUES
('$_POST[ModelType]','$_POST[CardType]','$_POST[OEMModel]','$_POST[OEMSku]','$_POST[Qty]','$_POST[RecvDate]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Batch Number $BatchNum Created";mysql_close($con)
?>
The only issue is that the QTY field is not inserting the data (I get a zero value). IN the database it is an integer field. From looking at the field setup in the table it is set for NOT NULL and you cannot get rid of the DEfault value of 0 (the not null). Could this be the problem?
Thanks,
Texman