Tutorial :why are form variables not available in this php code?



Question:

I have a form on my PHP page which performs some ajax validation (that's working). Here's a snippet (the live form has more fields than this)

    <form name="form" onSubmit="return validate_form();" action="submitform.php" method="post">          <table border="0" cellpadding="5" bgcolor="#000000">          <tr>              <td width="175">                  <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Requested Vendor TAG:</b> </font></div>              </td>              <td>                  <input type="text" name="VendorTAG" onblur="checktag();" maxlength="8"> <div id="vendtag"></div>              </td>          </tr>          <tr>              <td width="175">                  <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Contact Name:  </b> </font></div>              </td>              <td>                  <input type="text" name="ContactName" maxlength="50">              </td>          </tr>  

When I click the submit button, it loads this code:

<php ?  if(trim($VendorTAG) == '')     {        die('Vendor TAG cannot be blank');     }     else if(trim($ContactName) == '')     {        die('Contact Name cannot be blank');     }  ?>  

(again, there's more of the same, but this illustrates the point)

This all worked perfectly well until the last update from my hoster sometime over christmas, when the form stopped working - but I'm having real difficulty in finding out why..

The server is now running PHP 5.2.11 - am I doing something fundamentally wrong/stupid here?


Solution:1

In PHP 5.2 They got rid of register_globals. It is a security nightmare and should not be used.

Use $_POST instead to access Form Elements.

You can find more about register_globals here: http://us.php.net/manual/en/security.globals.php


Solution:2

POST vars are accessed like this: $_POST["varname"] and not like this: $varname. Alternatively, you can also access them through $_REQUEST too, but ultimately it's up to you.


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