Home Learning cascading style sheets Programming Web Design

Programming

Some simple ideas for PHP programming

1) Return an item posted from a form or a blank without warning message.

Warning messages can prove very annoying in PHP - never more than when they prevent a page redirect.

One way to overcome this is with a function to return blanks if the post is not set

function issetreturn($nameofvariable){

return (isset($variable))?$variable: '';

}

a second variation on this is

  function issetget($array,$enclosedtag) {

  return (isset($array[$enclosedtag]))?$array[$enclosedtag]: '';

 }

Obviously you can mess around with this so

return (isset($array[$enclosedtag]))?$array[$enclosedtag]: '0';
would be another option if you wish to return a zero to input into a database;

When using the issetreturn function you would declare something like this:

$sName=issetreturn($_REQUEST['clientname']);

Then the variable $sName could be used in an SQL insert statement for example.