Hey guys. I have a form where I input information into a database and also can upload a pic to my file server and save the url in my database. All the info is going in fine except my file upload script isn't working.
Here is my code:
<?php
// predefined variables
$target = "/home2/shb8_037/safetysmiles.com/public_html/upload/";
$target = $target . basename( $_FILES['photo']['name']);
$username = "";
$password = "";
$host = "";
$database = "shb4_055_5";
// connect to server and database or die trying
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die("Unable to connect to database");
//get info from textboxes
$name=$_POST['name'];
$bookingnumber=$_POST['bookingnumber'];
$bookingdate=$_POST['bookingdate'];
$race=$_POST['race'];
$sex=$_POST['sex'];
$height=$_POST['height'];
$weight=$_POST['weight'];
$dob=$_POST['dob'];
$arrestingagency=$_POST['arrestingagency'];
$bailamount=$_POST['bailamount'];
$charge=$_POST['charge'];
$pic=($_FILES['photo']['name']);
$incustody="Y";
// execute SQL query
$query = "INSERT INTO inmates (name,bookingnumber,bookingdate,race,sex,height,weight,dob,arrestingagency,bailamount,charge,incusto dy,photo)
VALUES ('$name','$bookingnumber','$bookingdate','$race','$sex','$height','$weight','$dob','$arrestingagency ','$bailamount','$charge','$incustody','$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']['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.";
}
$charge=nl2br($charge);
if(false === $rs = mysql_query($query))
{
debug($query);
}
else
{
echo " Inmate Database Updated<p>";
echo " $name <b>$bookingnumber</b> $dob<br>";
echo " $race $sex $height $weight<br>";
echo " $arrestingagency<br>";
echo " $bailamount<br>";
echo " $charge<br>";
echo " $bookingdate";
}
function debug($query)
{
if($_REQUEST['debug']) print $query;
}
?>
When I try to update it is adding the information I type in to my database, just it's not uploading the photo. I have read some and think it's possibly a way I'm assigning my upload folder. My server is somewhat complicated in file names so i've tried just upload/, public_html/upload/, safetysmiles.com/public_html/, shb8_037/safetysmiles.com/public_html/upload/ and even /home2/shb8_037/safetysmiles.com/public_html/upload/ and cannot get anything to work. Any suggestions I'd greatly appreciate.
Thanks.