title: PHP/MySQL - creating avatar upload function for users using BLOB
body: <p>I am creating a forum and am currently trying to allow my users to be able to update their profile picture (avatar). I am attempting to do this with BLOB. I am aware that storing images on a database is not a good idea but this is just a self-learning project and will unlikely be considered for real life use in the future.</p>
  
  <p>I am currently coming across the issue of the image not being saved in the database and resulting in the following error:</p>
  
  <pre><code>Notice: Undefined index: user_avatar in C:\wamp64\www\Latest_try\editprofile.php on line 24
  </code></pre>
  
  <p>I am a newb in php (clearly) and would appreciate if someone could help me understand what i  need to make it save the image to the database. </p>
  
  <p>I also wonder if i can save the image like this or would i need a complete seperate table that could then somehow link to the users information using a foreign key.</p>
  
  <p>Below is mysql table i am using in relation to the function and the issue.</p>
  
  <pre><code>mysql -&gt; describe users;
  +-----------------+-------------+------+-----+---------+--------------+
  | Field           | Type        | Null | Key | Default | Extra        |
  +-----------------+-------------+------+-----+---------+--------------+
  | user_Id         | int(8)      | NO   | PRI | NULL    |auto_increment|
  | user_name       | varchar(30) | NO   |     | NULL    |              |
  | user_pass       | varchar(255)| NO   |     | NULL    |              |
  | user_email      | varchar(255)| NO   |     | NULL    |              |
  | user_date       | datetime    | NO   |     | NULL    |              |
  | user_level      | int(8)      | NO   |     | NULL    |              |
  | user_description| varchar(255)| YES  |     | NULL    |              |
  | user_avatar     | longblob    | NO   |     | NULL    |              |
  +-----------------+-------------+------+-----+---------+--------------+
  8 rows in set (0.02 sec)
  </code></pre>
  
  <p>And here is my code for editprofile.php file.</p>
  
  <pre><code>&lt;?php
  include 'connect.php';
  include 'header.php';
  
  if(!isset($_SESSION['signed_in']))
  {
  //the user is not logged in.
  echo 'You must be &lt;a href="/Latest_try/signin.php"&gt;Signed in&lt;/a&gt; to add an image to your profile.'; 
  }
  else
  {
  if($_SERVER['REQUEST_METHOD']!='POST')
  {
  echo '&lt;form action="" method="post" enctype="multipart/form-data"&gt;
  Choose Image: &lt;input type="file" name="user_avatar"&gt;&lt;br/&gt;
  &lt;input type="submit" name="submit" value="Upload"&gt;
  &lt;/form&gt;';
  }
  else
  {
      $query = "INSERT INTO
                          users(user_avatar)
                      VALUES
                          ('" . mysqli_real_escape_string($link, $_POST['user_avatar']) . "',
                                NOW(),
                                '" . $_SESSION['user_id'] . "')";
  
  $result=mysqli_query($link, $query);
  if($result===false)
  {
      mysqli_error($link);
  }
       else
       {
           echo 'Your avatar has been updated!';
       }      
  }
  }
  ?&gt;
  </code></pre>