Lets try this here, I posted this in the General php forum earlier but thought I had it figured out and it stopped working so now I’m posting it here.
Here is my issue, I thought I had finally figured out how to upload an image to my server and store the image path in MySQL along with the rest of the form data. It did work the first few times and I was even able to get the image to display in a search page. Now here’s the problem, I did all that with a test input page and once I added all the variables and values to the PHP code for my production page it stopped working, it will still move the image to the folder but it stopped posting data to MySQL and wasn’t displaying any errors. I verified it was connecting to MySQL, the required database and table and it is but its not inputting any values in the table so I went back to square one and broke the script down to a simple form of 6 fields including an image and once again it moves the image to the folder and now it will post the form data in MySQL but it only posts the image name and not the path to the image.
So previously I noticed that the $target variable stores the path and that I didn’t have it in the INSERT function path, so I added $target into the values field and what do you know it was adding the image path to MySQL and I could display the image in a search form. Now it’s not doing that, it wont post to MySQL with $target in the values field or anywhere in the INSERT field. Someone please help this is driving me nuts!
Here is the html:
[code]
.auto-style1 { font-family: "Baskerville Old Face"; font-size: x-large; color: #FF0000; }ADD NEW ITEM
<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>
<p>
Manufactur:
</p>
<input type="text" name="manufacture" size=30 >
<br>
<br>
<input TYPE="submit" title="Add data to the Database" value="Submit">
</form>[/code]
And the PHP code:
[php]<?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”, “poopster”) 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))
{
//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.”;
}
?>[/php]
Just a note, I removed the $target from the values field because as the code is posted the form works but doesn’t post the path. it will store all the data from the input form in MySQL it just stores the name of the image and moves it to the upload/images folder. My images folder will never change so I guess I could make a static link the the folder and just pull the image name but I want the full path stored in MySQL.