Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ch2(working with forms)


Published on

chhom karath

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Ch2(working with forms)

  1. 1. Working with Forms
  2. 2. Superglobal Variables • A global variable is any variable declared at the "top level" of a script—that is, declared outside a function. • Superglobal variables are arrays built in to PHP.
  3. 3. The $_SERVER Array • The $_SERVER array contains elements set by your script's context, usually the server.
  4. 4. <html> <head> </head><body> <div> <?php If ( ! empty( $_POST['guess'] ) ) { print "last guess: ".$_POST['guess']; } ?> <form method="post" action="<?php print $_SERVER['PHP_SELF']?>"> <p> Type your guess here: <input type="text" name="guess" /> </p> </form> </div> </body> </html>
  5. 5. EX: action="<?php print $_SERVER['PHP_SELF']?>“ action="1.php" Note the PHP_SELF element in particular. We use it to point forms and links back at their enclosing scripts.
  6. 6. 1.html 2.php
  7. 7. 1.html 2.php Accessing Form Input with User-Defined Arrays
  8. 8. Combining HTML and PHP Code on a Single Page
  9. 9. Using Hidden Fields to Save State <? print $test;?> It is equivalent to <?=$test?>
  10. 10. Redirecting the User header("Location:congrats.html"); if ( ! headers_sent() ) { header( "Location:" ); exit; }
  11. 11. File Upload Forms and Scripts • We limited file uploads to 100KB