Trouble with Insert from php form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
texmansru47
Forum Commoner
Posts: 42
Joined: Mon May 12, 2008 11:27 am

Trouble with Insert from php form

Post by texmansru47 »

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
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

Re: Trouble with Insert from php form

Post by hannnndy »

i think you should change the query a bit

Code: Select all

$sql="INSERT INTO snabatch (`ModelType`, `CardType`, `OEMModel`, `OEMSku`, `Qty`, `RecvDate`)
VALUES
('". $_POST[ModelType] ."','". $_POST[CardType] ."','". $_POST[OEMModel] ."','". $_POST[OEMSku] ."','". $_POST[Qty] ."','". $_POST[RecvDate] ."');";
i mean some contactation and `` for the field names just like mysql and one thing else you can insert numbers --> int without any singel quote
texmansru47
Forum Commoner
Posts: 42
Joined: Mon May 12, 2008 11:27 am

Re: Trouble with Insert from php form

Post by texmansru47 »

Thank you for the inout, but I don't understand. Should I look at removing the double quotes from the $POST_[Qty] call? I assume that is what you are talking about.

Thanks,

Texman
texmansru47
Forum Commoner
Posts: 42
Joined: Mon May 12, 2008 11:27 am

Re: Trouble with Insert from php form

Post by texmansru47 »

Nevermind. I got it. Thank you very much for your assistance.

Texman
Post Reply