I dont think that it will be difficult for some of you on here to spot my flaw but I am trying to add a record and a image to a folder and register the name of the file along with the full path to the image in the mysql record.
The issue I am having is that the image is uploading OK but nothing from the form is uploading into the database.
My columns are named as
ID, Display Name, Model Type, Fix Type, Description, Price, image
Also...where would I put the http://www.XXXX.co.uk/images/catalog in my addrecord.php script so that it inserts it along with the file name of the file in the image column, so I can call this image later ?
This is my form
<form method="post" action="addrecord.php" enctype="multipart/form-data">
<p>
ID
</p>
<input type="text" name="nameid"/>
<p>
<p>
Display Part Name
</p>
<input type="text" name="namepart"/>
<p>
iPhone Model
</p>
<input type="text" name="nameiphone"/>
<p>
Fix Type
</p>
<input type="text" name="namefix"/>
<p>
Description
</p>
<input type="text" name="namedescription"/>
<p>
Price
</p>
<input type="text" name="nameprice"/>
<p>
Image:
</p>
<input type="file" name="photo">
<br/>
<br/>
<input TYPE="submit" name="upload" title="Insert Record" value="Insert Record"/>
</form>
This is the add record.php file
My code is
<?php
//This is the directory where images will be saved
$target = "/home/XXXX/public_html/images/catalog/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$ID=$_POST['nameid'];
$displayname=$_POST['namepart'];
$iphone=$_POST['nameiphone'];
$fix=$_POST['namefix'];
$description=$_POST['namedescription'];
$price=$_POST['nameprice'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("localhost", "XXXXXX", "iphone") or die(mysql_error()) ;
mysql_select_db("XXXXX_catalog") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO catrep (nameid,namepart,nameiphone,namefix,namedescription,nameprice,photo)
VALUES ('$ID','$displayname', '$iphone', '$fix', '$description','$price','$pic')") ;
//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['photo']['displayname']). " 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.";
}
?>
Thanks in advance
Martyn












