<td>Upload your pic</td>

      <td><?php if(!empty($picurl)){echo '<img src="'.$picurl.'" align="left"width="50px" height="50px"/>';}?>
      <input type="file" name="userfile"  ></td>
    </tr>
    <tr class="tableheader">
      <td colspan="4" class="last"><input name="submit" type="submit" class="button"  value="Update"/></td>
    </tr>
  </table>
</form>
<?php
if (isset($_POST["submit"])){

if($_FILES['userfile']['type']=="image/jpg" or
$_FILES['userfile']['type']=="image/jpeg" or
$_FILES['userfile']['type']=="image/gif" or
$_FILES['userfile']['type']=="image/png"){
echo "Error number: ".$_FILES['userfile']['error']."<br/>";
//$_Files is a global array,its 2 dimen
if(file_exists("image/".$_FILES['userfile']['name'])){
echo "file already exists in the folder";
}
else{
move_uploaded_file($_FILES['userfile']['tmp_name'],
"images/".$_FILES['userfile']['name']);
$uploaded_dir = "images/"; 
$filename = $_FILES["userfile"]["name"]; 
$path = $uploaded_dir . $filename;
}
}
}
if (isset($User_ID)){
$sql="UPDATE users SET PicUrl='$path' WHERE UserId='$User_ID'";
if (!mysql_query($sql)){
die('Error: '. mysql_error());
}
echo "Sucessfully Updated";
}

Just test if (isset ($_FILES["userfile"]) ). Only run your code if that is true. You can replace this code with that of line 12.

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.