Hi, I am trying to upload a single image but I keep getting an error that is at the bottom that tells me the upload failed -

Its really annoying & I have been going round in circles for days now -

here is my php

<?
	//Include database connection details
    require_once('includes/config.php');
	//Array to store validation errors
	$errmsg_arr = array();
	//Validation error flag
	$errflag = false;
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link)
	{
		die('Failed to connect to server: ' . mysql_error());
	}
//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db)
	{
		die("Unable to select database");
	}
//if submit button has been submiied to form
if(isset($_POST['submit']))
{

    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    $image = $_FILES['profile_image']['name'];
    $datetime = date('l jS F Y h:i:s'); //create date time

        //Image Size Validations
        if(($_FILES["profile_image"]["size"] / 1024)>1024){
            $errmsg_arr[]='Image should not be greater than 1(MB) 1024kb.';
            $errflag=true;
        }
        // Image validation
        if($image == '')
        {
            $errmsg_arr[] = 'Select a picture to upload to your gallery.';
            $errflag = true;
        }
        else // Image file type validation
        {
            $arr = explode('.', $image);
            $ext = strtolower($arr[1]);
            if($ext != "jpg" && $ext != "jpeg" && $ext != "png" && $ext != "gif")
            {
                $errmsg_arr[] = 'Profile image must be in JPG/JPEG/PNG/GIF format.';
                $errflag = true;
            }
        }
    
    if($errflag == false)
    {
        //Create INSERT query & insert to image gallery
        $qry = "INSERT INTO mgallery(id,gimg,title) VALUES('','$image_name','$title')";
                $result = @mysql_query($qry);          
        }
        else
        {
            die("UPLOAD failed");
        }
    }
?>

and the form to go with the above code is this

<table width="500" align="center">
  <tr>
       <td width="500" valign="top"><table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#A6D2FF"><img name="addpictures" src="http://www.website.com/members/images/Pictures128.png" width="64" height="64" hspace="5" vspace="5" align="middle" border="0" title="Add more pictures to your profile" alt="addpictures"><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='#2a4c79'>Upload new pictures to your online image gallery</font></td>
  </tr>
  <tr>
    <td align="center"><?php
        if(count($errmsg_arr) > 0)
        {
            echo '<ul class="err">';
            foreach($errmsg_arr as $msg)
            {
                echo '<li>',$msg,'</li>';
            }
            echo '</ul>';
            unset($errmsg_arr);
        }
        ?><form id="imgupload" name="imgupload" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
            <table width="500" border="0" align="center" cellpadding="2" cellspacing="0">				               
       			<tr>
       <th><div align="left">Upload Image to Gallery</div></th>
       <td><input name="profile_image" class="tb10" type="file" id="profile_image" title="browse for a new image to upload" size="35" /></td>
                </tr>
                <tr>
       <th><div align="left">Picture Comments</div></th>
       <td><textarea name="title2" id="title2" cols="35" rows="2" title="Add comments to your picture upload"></textarea></td>
                </tr>
                <tr>
                    <td><div align="left"></div></td>
                    <td><input type="submit" class="tb10" name="submit" value="Upload new image" /></td>
                </tr>
            </table>
        </form></td>
  </tr>
</table>
</td>
  </tr>
</table>

Im hoping someone can point me in the right direction as to where I am going wrong
cheers

Hi, I am making slow progress at the moment -

I have got the image uploading path uploading to the database corretly, But for some reason I am unable to upload the actual image to the destination path ??

if($errflag == false)
    {
			$qry = "INSERT INTO mgallery(id,uid,mpicture,title,date) VALUES('','$id','$image_name','$title',now())";
            $result = @mysql_query($qry);
	
			$image_ext = explode('.', $image);  //split the image name with respect of " . "
            $image_name = date('Ymdhis'). "." . $image_ext[1];  //create unique image name with present "date & time"

            $dest = "uploaded/207";
            
            $dest = $dest."/".$image_name;   
        
			$result = move_uploaded_file($_FILES['image_name']['tmp_name'], $dest); //upload image to the destination path
       //if($result){
      		mysql_query("update mgallery set mpicture ='http://www.website.com/members/$dest'"); //WORKING IMAGE UPLOAD 
				echo "Success";
			exit ();
		
			}
        else
        {
            die("Query failed2");
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.