I have a form which lets user insert data into the DB (this bit works). The script is also meant to upload the image to the server but it isn’t working. Here’s the script…
<?php
//This is the directory where images will be saved
$target = "images/"; $target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$title=$_POST['name']; $description=$_POST['description']; $step1=$_POST['step1']; $image1=($_FILES['photo']['name']);
$con = mysql_connect("xxxxxxxxxxxx","xxxxxxxxxxx","xxxxxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxxx", $con);
//Writes the information to the database
$sql="INSERT INTO
gallery (title, description, step1, image1)
VALUES ('$title','$description', '$step1', '$image1')";
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded, and your information has been added to the directory"; }
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file."; }
//DISCONNECT FROM DATABASE
mysql_close($con);
?>
I get this success message in the browser…
The file has been uploaded, and your information has been added to the directory
The message doesn’t echo the file no though and I think it should do. The is a directory in the correct location with permissions.
Can anyone help me with this please?