So here is my problem, I'm developing this for my business and what I'm doing is in an inventory form I display the image of the item in inventory, when I add a new item to the inventory the image is uploaded to the server stored in a folder and ideally the path to the image is stored in MySQL, well I had it working with the current script I'm using, I was even able to display the image in a search page. Put now it doesn't work, the image is still uploaded to the server and put in the correct folder but the path won't post in MySQL, as a matter of fact nothing posts to the database at all. Originally I was able to get the script to upload the image and move it to the permanent folder but it was only posting the form content and the name of the image not the path. I realized that the $target variable needed to be included in the INSERT function so I added $target to the values and it was working but now it's stopped, all I get is a confirmation that the image was posted and I can see it's in the folder but nothing gets posted to the database. I'm not sure if this is a problem with the code or if I have some issues with xampp so I broke the script down into a basic 6 input page and tried it with the $target variable not in the INSERT field and it will post the data but only the image name not the path but it does move the image to the correct folder. what am I doing wrong?
Note that I never get any type of errors from my PHP script at all, every time I get a confirmation that the file with the image name has been uploaded and the image does in fact upload to the correct folder but I get no errors at all unless I force an error by wrong password or such or create a parse error or something along that lines so I know the script is working.
here is my html:
<head> <style type="text/css"> .auto-style1 { font-family: "Baskerville Old Face"; font-size: x-large; color: #FF0000; } </style> </head> <span class="auto-style1">ADD NEW ITEM</span><form method="post" action="process_original.php" enctype="multipart/form-data"> <p> Serial Number: </p> <input type="text" name="s_number"> <p> Part Number: </p> <input type="text" name="p_number"> <p> Model Number: </p> <input type="text" name="m_number"> <p> Please Upload a Photo in gif, png, or jpg format. </p> <p> Photo: </p> <input type="file" name="p_image" size=35 > <p> Description: </p> <textarea cols="35" name="description" style="height: 35px"> </textarea> <p> Manufactur: </p> <input type="text" name="manufacture" size=30 > <br> <br> <input TYPE="submit" title="Add data to the Database" value="Submit"> </form>
and here is my PHP code:
<?php //This is the directory where images will be saved $target = "uploads/images/"; $target = $target . basename( $_FILES['p_image']['name']); //This gets all the other information from the form $var1=$_POST['description']; $var2=$_POST['p_number']; $pic=($_FILES['p_image']['name']); $var3=$_POST['m_number']; $var4=$_POST['s_number']; $var5=$_POST['manufacture']; // Connects to your Database mysql_connect("localhost", "root", "xxxxx") or die(mysql_error()) ; mysql_select_db("test") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO test (description,p_number,p_image,m_number,s_number,manufacture) VALUES ('$var1', '$var2', '$pic', '$var3', '$var4', '$var5')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['p_image']['tmp_name'], $target))<----I'm pretty sure this needs to be in the values but how? { //Tells you if its all ok echo "The file ". basename( $_FILES['p_image']['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."; } ?>