I'm new to this forum, and I'm having trouble with my project. I've used the same code for the other tables but this one won't work. Help! D:
This doesn't work:
<?php
$host="127.0.0.1";
$username="root";
$password="";
$db_name="nadel";
$tbl_name="soldprod";
mysql_connect("$host", "$username", "$password")or
die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sprodname=$_POST['sprodname'];
$spquant=$_POST['spquant'];
$scli=$_POST['scli'];
$spds=$_POST['spds'];
if(empty($sprodname) || empty($spquant) || empty($scli) || empty($spds))
{
echo "<script> alert('You did not fill out the required fields. ');
window.location.href='addsprod.php';</script> ";
}
else{
$sprodname = stripslashes($sprodname);
$spquant = stripslashes($spquant);
$scli = stripslashes($scli);
$spds = stripslashes($spds);
$sprodname = mysql_real_escape_string($sprodname);
$spquant = mysql_real_escape_string($spquant);
$scli = mysql_real_escape_string($scli);
$spds = mysql_real_escape_string($spds);
$sql="INSERT INTO soldprod(sp_name, sp_quantity, sp_cli_name, Date_sold)
VALUES ('$sprodname','$spquant','$scli','$spds')";
$result=mysql_query($sql);
echo "<script> alert('Successfully Added Sold Product!');
window.location.href='sprod.php';</script> ";
}
?>
But this works:
<?php
$host="127.0.0.1";
$username="root";
$password="";
$db_name="nadel";
$tbl_name="products";
mysql_connect("$host", "$username", "$password")or
die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$prodname=$_POST['prodname'];
$pquant=$_POST['pquant'];
$pprice=$_POST['pprice'];
$pdman=$_POST['pdman'];
$pdex=$_POST['pdex'];
if(empty($prodname) || empty($pquant) || empty($pprice) ||
empty($pdman)|| empty($pdex))
{
echo "<script> alert('You did not fill out the required fields. ');
window.location.href='addprod.php';</script> ";
}
else{
$prodname = stripslashes($prodname);
$pquant = stripslashes($pquant);
$pprice = stripslashes($pprice);
$pdman = stripslashes($pdman);
$pdex = stripslashes($pdex);
$prodname = mysql_real_escape_string($prodname);
$pquant = mysql_real_escape_string($pquant);
$pprice = mysql_real_escape_string($pprice);
$pdman = mysql_real_escape_string($pdman);
$pdex = mysql_real_escape_string($pdex);
$sql="INSERT INTO products(`product_name`, `prod_quantity`,
`prod_price`, `prod_manD`, `prod_expD`) VALUES
('$prodname','$pquant','$pprice','$pdman','$pdex')";
$result=mysql_query($sql);
echo "<script> alert('Successfully Added Product! ');
window.location.href='prod.php';</script> ";
}
?>
I don't know what went wrong D: