Tutorial :Need validation for a form in PHP not in Javascript?



Question:

Hai.. i already added javascript validation for my form.Its working fine.But mean while i ve to validate the same form using PHP also.

This is the form code:

  class airportclass{      function add_airport_frm(){      $errmsg=0;  <table>    <form action="" method="post" name="airport" >    <tr> <td colspan="2" align="center"><?php echo $errmsg; ?></td></tr>        <tr>        <td><strong>Code :</strong></td>        <td><input type="text" name="code" id="code"   /></td>      </tr>      <tr>        <td><strong>Name:</strong></td>        <td><input type="text" name="name" id="name"   /></td>      </tr>      </form>  </table>              }  

This is the PHP script in another file :

 if(isset($_POST['postcode']) && $_POST['postcode']!="")  {  $code=$_POST['code'];  $name=$_POST['name'];  $postcode=$_POST['postcode'];  $auth=$_POST['auth'];     if(trim($code)=='')     {        $errmsg = 'Please enter code';     }    }  

But its not working. Only javascript validation is working.PHP validation is not working.

Can any one suggest me????


Solution:1

As the form action="" is blank, the form is being posted to the same file. You indicated that you have your validation script in another file!


Solution:2

The $errmsg variable you're using is not global. It needs to be global if you intent to use it inside multiple functions.


Solution:3

You are checking against 'postcode', but postcode is nowhere set in your form.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »