now if i put a duplicate error php send a error message. great!
but if the entry is valid.. nothing happens. doesnt get inserted to DB and nothing on screen.
take a look at code anything wrong?
thanx
Code: Select all
<?php
$db = mysql_pconnect('****', '****', '****') or die ("Could not connect to database");
# mysql_select_db('models') or die ("Could not select database!");
# this is processed when the form is submitted
# back on to this page (POST METHOD)
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
# escape data and set variables
mysql_select_db('models') or die ("Could not select database!");
$P_Stock = stripslashes($_POST["P_Stock"]);
$P_Name = stripslashes($_POST["P_Name"]);
$P_Cat = stripslashes($_POST["P_Cat"]);
$P_Scale = stripslashes($_POST["P_Scale"]);
$P_Length = stripslashes($_POST["P_Length"]);
$P_Span = stripslashes($_POST["P_Span"]);
$P_Price = stripslashes($_POST["P_Price"]);
$P_Desc = stripslashes($_POST["P_Desc"]);
$sql1 = "select * from planes where P_Stock = '$P_Stock'";
$result1 = mysql_query($sql1,$db) or die("Execution failed: ".mysql_error());
if (!empty($P_Stock) && !empty($P_Name))
{
while ($row=mysql_fetch_array($result1))
{
if ($row["P_Stock"] == $_POST["P_Stock"])
{
print "<br><b>Duplicate Stockcode</b><br><br>";
}
else
{
$sql = "INSERT INTO planes (P_Stock, P_Name, P_Cat, P_Scale, P_Length, P_Span, P_Price, P_Desc) VALUES ('$P_Stock','$P_Name','$P_Cat','$P_Scale','$P_Length','$P_Span','$P_Price','$P_Desc')";
$result = mysql_query($sql, $db) or die ("Execution failed.");
move_uploaded_file($_FILES['file']['tmp_name'], '/var/users/modelair/modelaircraft.co.nz/htdocs/Pics/'.$_FILES['file']['name']);
echo 'File has been stored in your uploads directory.';
print "<br><b>new aircraft added</b><br><br>";
}
}
}
else
{
echo "<br><b>Make sure stock code AND name are filled out</b><br><br>";
}
}
?>