Simple Uploading File (Error) !

Discussion in 'PHP' started by Prog4rammer, Sep 14, 2010.

  1. #1
    Welcome every Guy's :)

    when I'm Coding Simple Uploading File Image appeared Error :

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Uploader Files</title>
    </head>
    
    <body>
    
    <?php
    
    require_once('Connection.php');
     
         if(isset($_POST['submit'])) 
         {
    	 
    	  $Type = $_POST['type'];
    	  $Image = $_FILES['file']['name'];
    	  $Image_type = $_FILES['file']['type'];
    	  $Image_size = $_FILES['file']['size'];
    	  
    	     if(!empty($Type) && !empty($Image))
    		 {
    		 
    		   if((($Image_type == 'image/gif') || ($Image_type == 'image/jpeg') || ($Image_type == 'image/png')) &&
    		      ($Image_size > 0) && ($Image_size <= GW_MAXFILESIZE))
    		   {
    		      
    			   if($_FILES['file']['error'] == 0)
    			   {
    			      $target = GW_UPLOADPATH . $Image;
    				  move_uploaded_file($_FILES['file']['tmp_name'],$target);
    				  
    				  $dbc = mysql_connect(DB_HOST,DB_USER,DB_PASS);
    				  mysql_select_db (DB_DataBase); 
    				  
    				  $QueryInsert = "INSERT INTO upload (type,image) VALUES ('$Type','$Image')";
    				  mysql_query($dbc,$QueryInsert);
    				  mysql_close($dbc);
    			   
    			   }
    			   else
    			   {
    			     echo '<p>Sorry, there was A Problem Uploading Your Image.</p>';
    			   }
    		   
    		   }
    		   else
    		   {
    		     echo '<p class="error">The Image must be a GIF, JPEG, or PNG image file no greater than ' 
    			 . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>';
    		   }
    		 
    		 }
    		 else
    		 {
    		     echo '<p class="error">Please Enter all of the Information to add your Image.</p>';
    		 }
         }
    
    ?>
    
    <H3>Simple Uploading Image File !</H3>
    
    <br /><br />
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
    
      <label>Type File :</label><br /><br />
      <input type="text" name="type" value="" /><br /><br />
      
      <label>Path File :<br /><br />
      <input type="file" name="file" id="file" /><br /><br />
      
      <input type="submit" value="Upload" name="submit" /><br /><br />
    </form>
    
    
    </body>
    </html>
    
    
    
    PHP:
    The Error in :

    
    $QueryInsert = "INSERT INTO upload (type,image) VALUES ('$Type','$Image')";
    
    PHP:
    mysql_query() expects parameter 1 to be string

    Thanks
     
    Prog4rammer, Sep 14, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Replace $Type with $Image_type

    Also consider sanitizing $Image_type...
     
    danx10, Sep 14, 2010 IP
  3. Prog4rammer

    Prog4rammer Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks mazako and danx10 :)

    I'm Solved the Problem in :

    
    
     $QueryInsert = "INSERT INTO upload (type,image) VALUES ('$Type','$Image')";
      mysql_query($QueryInsert);
    
    PHP:
    :D
     
    Prog4rammer, Sep 15, 2010 IP