Hi there,
Thanks everybody for replying 🙂
I changed the line of code on the form to:
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data"
This has fixed the 404 error, thank you very much 🙂
It has however created a new error...
I have tried to simpliy the page code by removing the other attributes in the table (that are inserted with the image) except for the image itself and the AnimalID (the Primary KEY Animal table of which image is an attribute of)......
When i run the page i get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Image`) VALUES ('52','./Images/linda.GIF')' at line 1
Please Note: The number 52 is the AnimalID number (most recent AnimalID record)....which is determind by another simple query that ORDERS Animal records by AnimalID Desc (SEE 1st 5 lines of code)
The animal table is never updated as the image field is alwasy empty (when checkedwith phpmyamdmin)...However the image is uploaded to the specificed directory.!!
If anybody could help me, that be great as i been stuck on this for a long time now and feel are close! 🙂
Heres the simplified page code:
<?php
mysql_select_db($database_woodside, $woodside);
$query_animal = "SELECT AnimalID FROM animal ORDER BY AnimalID DESC";
$animal = mysql_query($query_animal, $woodside) or die(mysql_error());
$row_animal = mysql_fetch_assoc($animal);
$totalRows_animal = mysql_num_rows($animal);
//image upload test
$file_dir = "C:/wamp/www/Woodside/Images/";
$link_dir = "./Images/";
$file_url = "http://localhost/woodside/Images/";
if (isset($_POST['submit']))
{
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_type = $_FILES['image']['type'];
$uploadfile = $file_dir.basename($image_name);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
// Query to insert data
mysql_select_db($database_woodside, $woodside);
$sql = "INSERT INTO `animal` (`AnimalID`,` `Image`) VALUES ('".$_POST['panimal']."','".$link_dir.$image_name."')";
echo "$sql<br />";
mysql_query($sql)or die(mysql_error());
} else {
echo "Possible file upload attack!\n";
}
//Uncomment these lines if you are having problems
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
print "<center>Image path: $file_dir<br>\n";
print "<center>Image name: $image_name<br>\n";
print "<center>Image size: $image_size bytes<br>\n";
print "<center>Image type: $image_type<p><br>\n\n";
print "<img src=\"$file_url/$image_name\"><p>\n\n";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data"><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br>
<input type="submit" name=submit value="Submit">
<input name="panimal" type="hidden" value="<?php echo $row_animal['AnimalID']; ?>" />
</form>
<?php
mysql_free_result($animal);
?>
Please help me! :eek: