0
 <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";
}
2
Contributors
1
Reply
19
Views
3 Years
Discussion Span
Last Post by andrevanzuydam
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.