<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 class="tableheader">
      <td colspan="4" class="last"><input name="submit" type="submit" class="button"  value="Update"/></td>
if (isset($_POST["submit"])){

if($_FILES['userfile']['type']=="image/jpg" or
$_FILES['userfile']['type']=="image/jpeg" or
$_FILES['userfile']['type']=="image/gif" or
echo "Error number: ".$_FILES['userfile']['error']."<br/>";
//$_Files is a global array,its 2 dimen
echo "file already exists in the folder";
$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, learning, and sharing knowledge.