Q:

Setting minimum length of characters for post

I got code for posting title and body of blog along with few other things. Now I want to set minimum length of characters for title and body using strlen, my code is
 if(isset($_POST['submit'])) {
   $title=$_POST['title'];
   $body=$_POST['body'];
   $category=$_POST['category'];
   $title = mysql_real_escape_string($title);
   $body = mysql_real_escape_string($body);
   $posted_by = $user;
   $bio = $bio;
   $id=$_SESSION['id'];
   $date = date ('Y-m-d');
   $body = htmlentities($body);
   if ($title && $body && $category) {
      $query = mysql_query("INSERT INTO blogs (id, title, body, posted_by, bio, category_id, posted) VALUES ('$id', '$title', '$body', '$posted_by','$bio', '$category', '$date')");
      if($query) {
        echo "posted";
      }
      else {
        echo "error";
      }
   }else {
    echo "data missing";
   }
}

This code works fine just want to insert minimum characters requirement for title and body. I have tried few if else statements with strlen but I am not programming expert so I get syntax errors.

A:

This may help you..
 if(isset($_POST['submit'])) {
           $title=$_POST['title'];
           if(strlen($title)<8)
           {
               //codes to handle error
           }

   $body=$_POST['body'];
   if(strlen($body)<80)
           {
               //codes to handle error
           }
   $category=$_POST['category'];
   $title = mysql_real_escape_string($title);
   $body = mysql_real_escape_string($body);
   $posted_by = $user;
   $bio = $bio;
   $id=$_SESSION['id'];
   $date = date ('Y-m-d');
   $body = htmlentities($body);
   if ($title && $body && $category) {
      if(strlen($title)>8 && strlen($body>80))
           {

      $query = mysql_query("INSERT INTO blogs (id, title, body, posted_by, bio, category_id, posted) VALUES ('$id', '$title', '$body', '$posted_by','$bio', '$category', '$date')");
           }
        else {
                  $query = 0;
              }
      if($query) {
        echo "posted";

      }
      else {
        echo "error";
      }
   }else {
    echo "data missing";
   }

