title: Inserting a statement requiring minimum number of characters
body: <p>Here I have a code which inserts data into db. It's working fine now, but I want the title to have a minimum of 4 characters and the body a minimum of 500.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['submit'])) {
    //get blog data
  $title=strip_tags($_POST['title']);
  $body=strip_tags($_POST['body']);
  $posted_by = $first_name;
  $category=$_POST['category'];
  $bio = $bio;
  $userid=$_COOKIE['user'];
  $date = date ('d-M-Y');
  if ($title &amp;&amp; $body &amp;&amp; $category) {
  $query = "INSERT INTO blogs (userid, title, body, posted_by, bio, category_id, posted) VALUES ('$userid', '$title', '$body', '$posted_by','$bio', '$category', '$date')";
   $run = mysqli_query($con,$query);
   if($query) {
      echo "posted";
    }
    else {
      echo "error";
    }
    }else {
      echo "data missing";
    }
    }
    ?&gt;
  </code></pre>
  
  <p>I tried the code below to put minimum requirements for the title and body, but it echoes the title error message whenever you submit data even when the title contains more than 5 characters.</p>
  
  <pre><code>  &lt;?php
    if(isset($_POST['submit'])) {
     //get blog data
     $title=strip_tags($_POST['title']);
     $body=strip_tags($_POST['body']);
     $posted_by = $first_name;
     $category=$_POST['category'];
     $bio = $bio;
     $userid=$_COOKIE['user'];
     $date = date ('d-M-Y');
     if (strlen($title&lt;5)) {
     echo "Title must be of minimum 5 characters";
     }
     else {
     if (strlen($body&lt;500)) {
      echo "Title must be of minimum 500 characters";
      }
      else {
      $query = "INSERT INTO blogs (userid, title, body, posted_by, bio, category_id, posted) VALUES ('$userid', '$title', '$body', '$posted_by','$bio', '$category', '$date')";
      $run = mysqli_query($con,$query);
      if($query) {
      echo "posted";
      }
      else {
       echo "error";
      }
      }
      }
      }
     ?&gt; 
  </code></pre>