11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 13• WORKING WITH HTML FORMSAssuming that the user completes both fields and clicks the Go! button, output similar to thefollowing will be displayed:Hi Bill!The address bill@example.com will soon be a spam-mag<strong>net</strong>!In this example, the form refers to the script in which it is found, rather than another script.Although both practices are regularly employed, it’s quite commonplace to refer to the originatingdocument and use conditional logic to determine which actions should be performed. In this case, theconditional logic dictates that the echo statements will only occur if the user has submitted (posted) theform.In cases where you’re posting data back to the same script from which it originated, as in thepreceding example, you can use the <strong>PHP</strong> superglobal variable $_SERVER['<strong>PHP</strong>_SELF']. The name of theexecuting script is automatically assigned to this variable; therefore, using it in place of the actual filename will save some additional code modification should the file name later change. For example, the tag in the preceding example could be modified as follows and still produce the same outcome:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!