Getting it right!
PHP Testing Server Variables Configuration continued:
To correctly set your PHP Testing Server Variables Configuration: And successfully code in PHP you need to read this first, else your code will throw simple error notices. Although not serious errors they are the cause of Under-defined-variables in your script notices. This is difficult to find ‘online and in forums’ and can be a headache for all newbies.
On most Linux/Lamp remote servers for PHP Testing Server Variables Configuration: they have set up a errors text file to catch such errors in your code scripts. Which can easily be viewed in the servers directory files.
To correctly set variables on a Testing Server depending on setup is to use the below types to define those variables. Otherwise you may get this error, Under-defined-variables. Variable names in PHP start with a dollar sign. ($) Depending on your version of PHP and setup. You can access the form data in three ways. These methods do not have official names, so are nicknamed short, medium and long style. You may access the contents of there fields in the following ways.
1) $tireqty //short style – ( PHP Testing Server Configuration: Under-defined-variables errors …)
2) $_POST[‘tireqty’] //medium style- ( PHP Testing Server Configuration: Under-defined-variables no errors … )
3) $HTTP_POST_VARS[‘tireqty’] //Long style ( PHP Testing Server Configuration: Under-defined-variables to long obsolete…)
- short style is convenient but requires the register_global s configuration settings to be turned on.
- medium style is the recommended approach.
- Long style is the most verbose. this can be disabled via the register_ long_arrays configuration directive which improves performance. This method is also sometimes adopted by remote servers as it may likely be installed on old servers.The following examples use medium style if configured as above. And is what is coded in sample cart: See download link at bottom of page
Creating medium variable names examples !
$oilqty = $_POST[‘oilqty’];
$sparkqty = $_POST[‘sparkqty’];
To correctly Configure Testing Server Environment Settings use any of the following.
- E-Notices can be disabled in the PHP.ini config text file to stop all non- critical errors. You can also redirect all notices to a error text file so you can view them. This is mostly used by remote servers.
- You can use the ISSET function to set the variable.
- A ampersand can also be used to suppress the error. @ this is placed in front of the defined variable.
If you don’t get rid of Under-defined-variables-simple-errors, these will show up in your browser window, these errors can be simple ignored because they are just PHP notices but are annoying to see in the browser window and must be sorted if your site is live or in production.