Iam a newbie to php. Iam builing ainventory control system. My problem is with date(type = date) and quantity(decimal). When i insert some values for these categories they show and store as zeros. But varchar types insert correctly. Hope u guys will help me to debug this. thanks in advance.
This is my code
<?php
session_start();
include("config.php");
$generalname = mysql_real_escape_string($_POST['generalname']);
$Scientificname = mysql_real_escape_string($_POST['Scientificname']);
$quantity = mysql_real_escape_string($_POST['quantity']);
$type = mysql_real_escape_string($_POST['type']);
$unit = mysql_real_escape_string($_POST['unit']);
$date = mysql_real_escape_string($_POST['date']);
$qry_add = "INSERT INTO chemical
(generalname, Scientificname, quantity, type, unit, date )
VALUES ('$generalname', '$Scientificname', 'quantity', '$type', '$unit','$date') ";
$count = mysql_query("SELECT COUNT(chemicalname) FROM chemical WHERE chemical name='$generalname'");
if($count==1)
{
echo "<font color=red> Duplicate Entry. Please Verify Chemical name </font>";
}
else
{
if($result=mysql_query($qry_add))
{
echo '<script language="javascript">';
echo 'alert("you have successfully added one Chemical!" );';
echo '</script>';
}
else
{
echo "<br><font color=red size=+1 >Problem in Adding !</font>" ;
echo "ERROR - unable to add new chemical!<br>";
$SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."<BR><BR>";
echo "$SQLError";
mysql_close();
}
}
?>
This is my table structure
CREATE TABLE IF NOT EXISTS chemical (
id int(50) NOT NULL AUTO_INCREMENT,
generalname varchar(100) NOT NULL,
Scientificname varchar(100) DEFAULT NULL,
quantity decimal(10,2) DEFAULT NULL,
type varchar(50) DEFAULT NULL,
unit varchar(50) DEFAULT NULL,
date date NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
This is my input
general name > HCl
Scientific name > dd
Quantity > 500.5
type > liquid
unit > l
date > 2012-02-05
This is what system shows in view.php page
general name > HCl
Scientific name > dd
Quantity > 0.00
type > liquid
unit > l
date > 0000-00-00
This is how table back up file show the entry
Dumping data for table chemical
INSERT INTO chemical (id, generalname, Scientificname, quantity, type, unit, date) VALUES
(2, 'HCl', 'dd', '0.00', 'liquid', 'l', '0000-00-00');