[SOLVED] query help
Posted: Mon Sep 13, 2004 10:01 pm
hi guys,
i had this problem a while ago and Feyd told me to look up what a
query_string returns and i have done that but still not working.
i want it to validate for duplicate entrys, but its not, its just inserting them.
thanx guys.
i had this problem a while ago and Feyd told me to look up what a
query_string returns and i have done that but still not working.
i want it to validate for duplicate entrys, but its not, its just inserting them.
thanx guys.
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"]);
if (!empty($P_Stock) && !empty($P_Name))
{
$sql1 = "select * from planes where P_Stock = '$P_Stock'";
$result1 = mysql_query($sql1,$db) or die("Execution failed: ".mysql_error());
if (!$sql1);
{
$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.';
echo "<br><b>new aircraft added</b><br><br>";
}
else
{
echo "<br><b>Duplicate Stockcode</b><br><br>";
}
}
else
{
echo "<br><b>Make sure stock code AND name are filled out</b><br><br>";
}
}
?>