title: Uploading photo to server to use as profile picture.
body: <p>I have a problem that I'm working with right now. Currently I have a registration form that accepts a few fields from the user and a picture upload field for the profile picture. Currently the profile picture name is being inserted into the database but when viewing the folder of the target location there is no sign of the picture. Right now the page goes white and loads a little tiny broken picture in the top left hand corner. Any advice?</p>
  
  <p><strong>Profile Page</strong></p>
  
  <pre><code>&lt;?PHP
  ob_start();
  error_reporting(E_ALL);
  ini_set('display_errors',"On");
  session_start();
  if (!isset($_SESSION['username'])) {
      header('location:login.php');
  }
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;style&gt;
  
  &lt;/style&gt;
  &lt;!--[if lt IE 9]&gt;
  
          &lt;script src="http://html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
  
      &lt;![endif]--&gt;        
  
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;  $(document).ready(function(){
  
                  $('#login-trigger').click(function(){
  
                      $(this).next('#login-content').slideToggle();
  
                      $(this).toggleClass('active');                  
  
  
  
                      if ($(this).hasClass('active')) $(this).find('span').html('&amp;#x25B2;')
  
                          else $(this).find('span').html('&amp;#x25BC;')
  
                      })
  
            });
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;header class="cf"&gt;
  
  &lt;nav&gt;&lt;/nav&gt;
  
  &lt;/header&gt;
  &lt;h1 style="text-align:center"&gt; The Animator - BETA&lt;/h1&gt;
  &lt;hr /&gt;
  &lt;div id="nav" style="text-align:center"&gt;
  &lt;ul style="text-align:center"&gt;
  &lt;li&gt;&lt;a href= "theanimator.html" &gt;&lt;strong&gt;Home&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;strong&gt;&lt;li&gt;&lt;a href= "industrial.html" &gt;Industrial&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "educational.html" &gt;Education&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "independent.html"  &gt;Independent&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "emergent.html"  &gt;Emergent&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "team.html" &gt;Team&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "project.html"  &gt;Project&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "budget.html" &gt;Budget&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href= "profile.html" &gt;Profile&lt;/a&gt;&lt;/li&gt;&lt;/strong&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;hr /&gt;
  &lt;div style="padding-left:19%"&gt;&lt;input type="text" value="search" /&gt;
  &lt;input type="button" value="Search!" name="search"/&gt;
  &lt;/div&gt;
  &lt;h1 style="text-align:center"&gt;Profile&lt;/h1&gt;
  &lt;div style="padding-left:15%; padding-right:15%; font-family: Arial, Helvetica, sans-serif;"&gt;
    &lt;div style="font-size:18px; text-align:center; font-family: Arial, Helvetica, sans-serif;"&gt;
      &lt;p&gt;
        &lt;?php 
  
      $querytest = "SELECT * FROM account WHERE idaccount = " . $_GET['idaccount'];
      $result = mysql_query($querytest);
  
      echo $_SESSION['idaccount'];
    ?&gt;
      &lt;/p&gt;
      &lt;p&gt;
        &lt;?php
  
  echo $_SESSION['username'];
    ?&gt;
      &lt;/p&gt;
    &lt;/div&gt;
    &lt;p style="text-align:center;"&gt;&lt;?php echo $_SESSION['email'];?&gt;&lt;/p&gt;
      &lt;div style="font-size:18px; width:100px; text-align:left; margin-left:201px; padding-left:10pt"&gt;Specialties&lt;/div&gt;
  &lt;/div&gt;
    &lt;div style="width:100%; float:left;"&gt;
    &lt;div style="width:30%"&gt;
    &lt;?php
   $db_name = "animator"; // Database name
    $link = mysql_connect('localhost', 'root', 'admin');
  if (!$link) {
  die('Could not connect: ' . mysql_error());
  }
  //echo 'Connected successfully';
  mysql_select_db($db_name) or die("Could not connect to Database" .mysql_error());
    $result = mysql_query("SELECT * FROM animator.account WHERE idaccount=" . $_SESSION['idaccount'] . ";");
    if (!$result) { // add this check.
      die('Invalid query: ' . mysql_error());
  }
  while($row = mysql_fetch_array($result))
  {
   header("Content-type: image/jpeg");
       echo mysql_result($result, 0);
  } 
  
     ?&gt;
     &lt;/div&gt;
    &lt;div class="previous_work" id="previous_work" style="width:70%; float:left; margin-left:2%;"&gt;
    &lt;hr /&gt;
    &lt;li&gt;3D Animation&lt;/li&gt;
    &lt;li&gt;Scriptwriting&lt;/li&gt;
    &lt;li&gt;CGI Animation &lt;/li&gt;
  &lt;/div&gt;
  &lt;hr /&gt;
    &lt;/div&gt;
    &amp;nbsp;
    &lt;hr /&gt;
  &lt;?php echo $_SESSION['bio']; ?&gt;
  &lt;/p&gt;
  &lt;/div&gt;
    &lt;/p&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;/div&gt;
  &lt;div id="footer"&gt; &lt;hr /&gt;
    &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;a href="about.html"&gt;About The Animator&lt;/a&gt; | &lt;a     href="contact.html"&gt;Contact&lt;/a&gt; | &lt;a href="privacy.html"&gt;Privacy Policy&lt;/a&gt; | &lt;a     href="faq.html"&gt;FAQ&lt;/a&gt;&lt;/u&gt;&lt;/strong&gt;&lt;u&gt; | &lt;strong&gt;&lt;a     href="questionnaire.html"&gt;Questionnaire&lt;/a&gt; |&lt;/strong&gt;&lt;/u&gt; &lt;strong&gt;&lt;a     href="reports.html"&gt;Admin Reports&lt;/a&gt; |&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>REGISTER PAGE WITH PHOTO UPLOAD</strong></p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors',"On");
  include ('database_connection.php');
  $target = "/var/www/profile";
  
  if (isset($_POST['formsubmitted'])) {
      $error = array();//Declare An Array to store any error message  
      if (empty($_POST['name'])) {//if no name has been supplied 
          $error[] = 'Please Enter a name ';//add to array "error"
      } else {
          $name = $_POST['name'];//else assign it a variable
      }
  
      if (empty($_POST['e-mail'])) {
          $error[] = 'Please Enter your Email ';
      } else {
  
  
          if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
             //regular expression for email validation
              $Email = $_POST['e-mail'];
          } else {
               $error[] = 'Your EMail Address is invalid  ';
          }
  
  
      }
  
  
      if (empty($_POST['Password'])) {
          $error[] = 'Please Enter Your Password ';
      } else {
          $Password = $_POST['Password'];
      }
  
  
      if (empty($error)) //send to Database if there's no error '
  
      { // If everything's OK...
  
          // Make sure the email address is available:
          $query_verify_email = "SELECT * FROM account  WHERE email ='$Email'";
          $result_verify_email = mysqli_query($dbc, $query_verify_email);
          if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false)
              echo ' Database Error Occured ';
          }
  
          if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .
  
  
              // Create a unique  activation code:
              $activation = md5(uniqid(rand(), true));
              $target = $target . basename($_FILES['photo']['name']);
  
  //This gets all the other information from the form
              $pic=($_FILES['photo']['name']);
              if(!isset($_FILES['photo'])) {
  $error[] = "No photo selected !";
  }
  
  
  
              $query_insert_user = "INSERT INTO `account` ( `username`, `passwords`, `email`, `picture`) VALUES ( '$name', '$Password', '$Email ' , '$pic')";
  
  
              $result_insert_user = mysqli_query($dbc, $query_insert_user);
              if (!$result_insert_user) {
                  echo 'Query Failed ';
              }
  
              if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.
  
  
                  // Send the email:
                  $message = " To activate your account, please click on this link:\n\n";
                  $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&amp;key=$activation";
                  mail($Email, 'Registration Confirmation', $message, 'From: systemadminstrator@theanimator.com');
  
                  // Flush the buffered output.
  
  
                  // Finish the page:
                  echo '&lt;div class="success"&gt;Thank you for
  registering! A confirmation email
  has been sent to '.$Email.' Please click on the Activation Link to Activate your account &lt;/div&gt;';
  
  
              } else { // If it did not run OK.
                  echo '&lt;div class="errormsgbox"&gt;You could not be registered due to a system
  error. We apologize for any
  inconvenience.&lt;/div&gt;';
              }
  
          } else { // The email address is not available.
              echo '&lt;div class="errormsgbox" &gt;That email
  address has already been registered.
  &lt;/div&gt;';
          }
  
      } else {//If the "error" array contains error msg , display them
  
  
  
  echo '&lt;div class="errormsgbox"&gt; &lt;ol&gt;';
          foreach ($error as $key =&gt; $values) {
  
              echo '  &lt;li&gt;'.$values.'&lt;/li&gt;';
  
  
  
          }
          echo '&lt;/ol&gt;&lt;/div&gt;';
  
      }
  
      mysqli_close($dbc);//Close the DB Connection
  
  } // End of the main Submit conditional.
  
  
  
  ?&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Registration Form&lt;/title&gt;
  
  
  
  
  
  &lt;style type="text/css"&gt;
  body {
      font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
      font-size:12px;
  }
  .registration_form {
      margin:0 auto;
      width:500px;
      padding:14px;
  }
  label {
      width: 10em;
      float: left;
      margin-right: 0.5em;
      display: block
  }
  .submit {
      float:right;
  }
  fieldset {
      background:#EBF4FB none repeat scroll 0 0;
      border:2px solid #B7DDF2;
      width: 500px;
  }
  legend {
      color: #fff;
      background: #80D3E2;
      border: 1px solid #781351;
      padding: 2px 6px
  }
  .elements {
      padding:10px;
  }
  p {
      border-bottom:1px solid #B7DDF2;
      color:#666666;
      font-size:11px;
      margin-bottom:20px;
      padding-bottom:10px;
  }
  a{
      color:#0099FF;
  font-weight:bold;
  }
  
  /* Box Style */
  
  
   .success, .warning, .errormsgbox, .validation {
      border: 1px solid;
      margin: 0 auto;
      padding:10px 5px 10px 50px;
      background-repeat: no-repeat;
      background-position: 10px center;
       font-weight:bold;
       width:450px;
  
  }
  
  .success {
  
      color: #4F8A10;
      background-color: #DFF2BF;
      background-image:url('images/success.png');
  }
  .warning {
  
      color: #9F6000;
      background-color: #FEEFB3;
      background-image: url('images/warning.png');
  }
  .errormsgbox {
  
      color: #D8000C;
      background-color: #FFBABA;
      background-image: url('images/error.png');
  
  }
  .validation {
  
      color: #D63301;
      background-color: #FFCCBA;
      background-image: url('images/error.png');
  }
  
  
  
  &lt;/style&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  
  &lt;form action="registeraccount.php" method="post" class="registration_form" enctype="multipart/form-data"&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Registration Form &lt;/legend&gt;
  
      &lt;h2 style="text-align:center"&gt;Create an account!&lt;/h2&gt;
      &lt;p style="text-align:center"&gt; &lt;span&gt;Already a member? &lt;a href="login.php"&gt;Log in&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;
  
      &lt;div class="elements"&gt;
        &lt;label for="name"&gt;Name :&lt;/label&gt;
        &lt;input type="text" id="name" name="name" size="25" /&gt;
      &lt;/div&gt;
      &lt;div class="elements"&gt;
        &lt;label for="e-mail"&gt;E-mail :&lt;/label&gt;
        &lt;input type="text" id="e-mail" name="e-mail" size="25" /&gt;
      &lt;/div&gt;
      &lt;div class="elements"&gt;
        &lt;label for="Password"&gt;Password:&lt;/label&gt;
        &lt;input type="password" id="Password" name="Password" size="25" /&gt;
        &lt;p&gt;
                Photo:
              &lt;/p&gt;
              &lt;input type="hidden" name="size" value="350000"&gt;
              &lt;input type="file" name="photo"&gt; 
              &lt;p&gt;
        &lt;/div&gt;
  
        &lt;br /&gt;
  
      &lt;div class="submit"&gt;
       &lt;input type="hidden" name="formsubmitted" value="TRUE" /&gt;
        &lt;input type="submit" value="Register" /&gt;
  
      &lt;/div&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;button onclick="window.location='theanimator.html';"&gt;Go Back!&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>