ok so here is the mock form that I made in order to test the code as I was writing it:
<html>
<body>
<form action = "insert.php" method = "post"></br>
Make: <input type = "text" name = "make" /></br>
Model: <input type = "text" name = "model" /></br>
Year: <input type = "text" name = "year" /></br>
Odometer: <input type = "text" name = "mile" /></br>
Description: <TEXTAREA name = "des" ROWS = 5 COLS = 15/>
</TEXTAREA></br>
<input type = "submit" />
</form>
</body>
</html>
Here is the code inserting the information into the vehicle table
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Vehicles (year, make, model, mileage, description)
VALUES
('$_POST[year]','$_POST[make]','$_POST[model]','$_POST[mile]',
'$_POST[des]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
this is the form i made to test my upload code
<html>
<body>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
and finally the code for the upload itself
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("VPics/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"VPics/" . $_FILES["file"]["name"]);
echo "Stored in: " . "VPics/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
Everything I have been getting for inserting the vehicle ID into a table for reference, so that the pictures are matched propperly to the vehicles, looks to be a temperary fix, because the code would change the next time it was called and if someone pulled up and tried to add pictures to a previous entry the reference ID would have changed. where am I going wrong?