title: How to add image upload in php and mysql?
body: <p>How to add image upload to this code? Here's the code where you write a news. I would like to add image upload to this code, so I could write a news with a picture. It prints only the text now.</p>
  
  <pre><code>&lt;?php
          if ( !isset($database_link))
          {
              die(header('location: index.php?page=news'));
          }
          if ( !isset($_GET['category_id']))
          {
              die(header('location: index.php?page=news'));
          }
          $category_id = ($_GET['category_id'] * 1);
  
  
  
          $news_title = '';
          $news_content = '';
          $user_id = $_SESSION['user']['user_id'];
  
  
          if (isset($_POST['news_submit']))
          {
              $form_ok = true;
  
              $news_title = mysqli_real_escape_string($database_link, $_POST['news_title']);
              $news_content = mysqli_real_escape_string($database_link, $_POST['news_content']);
  
  
  
  
              if ($news_title == '')
              {
                  $form_ok = false;
                  echo '&lt;p class="alert alert-error"&gt;Please complete&lt;/p&gt;';
              }
              if ($news_content == '')
              {
                  $form_ok = false;
                  echo '&lt;p class="alert alert-error"&gt;Please complete&lt;/p&gt;';
              }
  
  
                      if ($form_ok) 
  
              {
                  $query = "
                      INSERT INTO news 
                          (news_title, news_content, news_postdate, fk_users_id, fk_categories_id) 
                      VALUES 
                          ('$news_title','$news_content', NOW(), '$user_id', '$category_id')";
                  $result = mysqli_query($database_link, $query) or if_sql_error_then_die(mysqli_error($database_link), $query);
  
                  if ($result)
                  {
                      generateRss($category_id);
                      die(header('location: index.php?page=news&amp;category_id='.$category_id));
                  }
              }
          }
      ?&gt;
  
      &lt;div class="col-lg-12"&gt;
        &lt;form method="post" role="form"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="news_title"&gt;News Titel&lt;/label&gt;
            &lt;input type="text" class="form-control" name="news_title" id="news_title" placeholder="Nyheds Titel" value="&lt;?php echo $news_title; ?&gt;" maxlength="64" required&gt;
          &lt;/div&gt;
          &lt;div class="form-group "&gt;
            &lt;label for="news_content"&gt;News text&lt;/label&gt;
            &lt;textarea class="form-control" id="editor1" name="news_content" placeholder="Nyheds Tekst" rows="10" cols="80" required&gt;
  
                  &lt;/textarea&gt;
            &lt;script&gt;
  
                      CKEDITOR.replace( 'editor1' );
                  &lt;/script&gt; 
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="category_id"&gt;News&lt;/label&gt;
            &lt;select class="form-control-select" name="category_id" id="category_id"&gt;
              &lt;option value="0"&gt;Choose News&lt;/option&gt;
              &lt;?php
                          $query = "SELECT category_id, category_title FROM categories ORDER BY category_title ASC";
                          $result = mysqli_query($database_link, $query) or if_sql_error_then_die(mysqli_error($database_link), $query);
                          if (mysqli_num_rows($result) &gt; 0)
                          {
                              while ($row = mysqli_fetch_assoc($result))
                              {
                                  $selected = ($category_id == $row['category_id'] ? ' selected="selected"' : '');
                                  echo '&lt;option value="'.$row['fk_categories_id'].'"'.$selected.'&gt;'.$row['category_title'].'&lt;/option&gt;';
                              }
                          }
                      ?&gt;
            &lt;/select&gt;
          &lt;/div&gt;
          &lt;input type="submit" class="btn-send" style="background-color:#D67400; border-color:#D67400;" name="news_submit" value="Gem" /&gt;
          &lt;a href="index.php?page=news&amp;amp;category_id=&lt;?php echo $category_id; ?&gt;" class="btn btn-default" onclick="return confirm('Are you sure you want to cancel?')"&gt;Annuller&lt;/a&gt;
        &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Here is the code where it gets from database  and then prints the images on this. It only prints text without pictures as you can see.</p>
  
  <pre><code> &lt;?php
      if ( !isset($database_link))
      {
          die(header('location: index.php'));
      }
  
      &gt; $query = "  SELECT news_id, news_title, news_content, news_postdate,
      &gt; category_id, category_title, user_name 
      &gt;               FROM news
      &gt;               INNER JOIN categories ON categories.category_id = news.fk_categories_id
      &gt;               INNER JOIN users ON users.user_id = news.fk_users_id
      &gt;               ORDER BY news_postdate DESC
      &gt;               LIMIT 10";
      &gt;     $result = mysqli_query($database_link, $query) or if_sql_error_then_die(mysqli_error($database_link), $query);
      &gt;     if (mysqli_num_rows($result) &lt;= 0)
      &gt;     {
  
          echo '  &lt;p class="alert alert-info"&gt;emty...&lt;/p&gt;';
      }
      else
      {
  
          while ($row = mysqli_fetch_assoc($result))
          {
              $news_id = $row['news_id'];
              $news_title = $row['news_title'];
              $news_content = substr(strip_tags($row['news_content']), 0, 200).'...';
              $news_postdate = strftime('%A d. %d. %B %Y  %H:%M', strtotime($row['news_postdate']));
              $user_name = $row['user_name'];
              $category_id = $row['category_id'];
              $category_title = $row['category_title'];
              echo '
                      &lt;section class="news_category"&gt;
                          &lt;h1&gt;'.$news_title.'&lt;/h1&gt;
                          &lt;p1&gt;  '.$news_postdate.' &lt;/p1&gt;
                          &lt;p&gt;&lt;a href="index.php?page=news&amp;amp;category_id='.$category_id.'&amp;amp;news_id='.$news_id.'"&gt;'.$news_content.'&lt;/a&gt;&lt;/p&gt;
                          &lt;em&gt; '.$user_name.', in category: '.$category_title.'&lt;/em&gt;&lt;hr /&gt;
                      &lt;/section&gt;';
                      echo '&lt;div class="spacer"&gt; &lt;/div&gt;';
          }
      }
  </code></pre>