title: Live validation in php
body: <p>I got a table and i have added 2 buttons to add or update information.</p>
  
  <p><strong>I wanna make a validation in the "description" field where **YOU CAN ONLY WRITE LETTERS AND LESS THAN 255 CHARACTERS ; AND IN THE "name" FIELD YOU CAN ONLY WRITE LESS THAN 50 CHARACTERS.  ANYWAY I CAN NOT CLICK ON THE BUTTON "SAVE" OR "ADD" RESPECTIVELY (THE BUTTON IS LOCKED UNTIL EVERYTHING IS RIGHT).</strong></p>
  
  <p><strong><em>Also the page must show IN REAL TIME (BEFORE CLICKING THE BUTTON) THE ERRORS IN EACH FIELD.</em></strong></p>
  
  <p>Here is my code, when adding new informationin the table:</p>
  
  <pre><code>  &lt;?php include('connect.php'); 
      $error="";
  
      if(isset($_POST['btnsave']))
      {
          $career_id=$_POST['carrera'];
          $name=$_POST['txtname'];
          $description=$_POST['txtdescription'];
          $hourss=$_POST['txthours'];
  
  
          if($_POST['txtid']=="0")
          {
  
              $a_sql=mysql_query("INSERT INTO subjects VALUES('','$career_id','$name','$description','$hourss')");
              if($a_sql)
              {
  
                  header("location:index.php");//
  
              }
  
  
          }else{
  
              echo "Update";
          }
  
      }
  
      $sqlm = mysql_query("SELECT * FROM careers");
      $options = "";
          while($result = mysql_fetch_array($sqlm)){
      $options .= "&lt;option value='".$result['id']."'&gt;".$result['name']."&lt;/option&gt;";
  }
  
  
  ?&gt;
  
              &lt;h2 align="center"&gt;ADD NEW SUBJECT&lt;/h2&gt;
              &lt;form method="Post"&gt;
                  &lt;table align="center"&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Career:&lt;/td&gt;
                       &lt;td&gt;&lt;select name='carrera'&gt;&lt;?php echo $options; ?&gt;&lt;/select&gt;&lt;input type="hidden" name="txtid" value="0" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Name:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='txtname'/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Description:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='txtdesription'/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Hours:&lt;/td&gt;
                          &lt;td&gt;
                          &lt;select name='txthours'/&gt;
                              &lt;option &lt;?php if($hourss=='1') echo 'selected' ; ?&gt; value="2"&gt;2 (two)&lt;/option&gt;
                              &lt;option &lt;?php if($hourss=='1') echo 'selected' ; ?&gt; value="4"&gt;4 (our)&lt;/option&gt;
                              &lt;option &lt;?php if($hourss=='1') echo 'selected' ; ?&gt; value="6"&gt;6 (six)&lt;/option&gt;
                              &lt;option &lt;?php if($hourss=='1') echo 'selected' ; ?&gt; value="8"&gt;8 (eight)&lt;/option&gt;
                              &lt;option &lt;?php if($hourss=='1') echo 'selected' ; ?&gt; value="10"&gt;10 (ten)&lt;/option&gt;
                          &lt;/select&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;input type='submit' value=save name='btnsave'/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                  &lt;/table&gt;
  
  
              &lt;/form&gt;
  </code></pre>
  
  <p>And the another code updates the information in the table:</p>
  
  <pre><code>  &lt;?php include('connect.php'); 
  
      $error="";
  
  
  if(isset($_GET['edit']))
  {
          $ident=$_GET['iden'];
          $row=mysql_query("SELECT * FROM subjects WHERE id=$ident");
          $st_row=mysql_fetch_array($row);
  
  
  }
  
  
  ?&gt;
  
              &lt;h2 align="center"&gt;UPDATE SUBJECT&lt;/h2&gt;
              &lt;form method="Post" action=''&gt;
                  &lt;table align="center"&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Career:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='txtcarreras_id' value="&lt;?PHP echo $st_row['career'] ?&gt;"/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Name:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='txtnombre' value="&lt;?PHP echo $st_row['name'] ?&gt;"/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Description:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='txtdescripcion' value="&lt;?PHP echo $st_row['description'] ?&gt;"/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;Hours:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='txtcarga_horaria' value="&lt;?PHP echo $st_row['hours'] ?&gt;"/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;    
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;input type='submit' value="save" name='btnsave'/&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
                  &lt;/table&gt;
  
  
              &lt;/form&gt;
  
  
  &lt;?php
      if(isset($_POST['btnsave']))
      {
          $career_id=$_POST['txtcarreras_id'];
          $name=$_POST['txtnombre'];
          $description=$_POST['txtdescripcion'];
          $hours=$_POST['txtcarga_horaria'];
  
          $a_sql=mysql_query("UPDATE materias SET career='$career_id', name='$name', description='$description', hours='$hours' WHERE id='$ident'");
              if($a_sql)
              {
  
                  header("location:index.php");
  
              }
  
  
          }
  ?&gt;
  </code></pre>
  
  <p>I don't know what to do :S</p>