Section A.10. Chapter 10


A.10. Chapter 10


Solution to Question 10-1

The super global variable $_SERVER['PHP_SELF'] always returns the name of the running PHP script. You can rename a script containing the global variable, and your code automatically uses the new script name to process the results.


Solution to Question 10-2

The code to create a username and password form that processes the values is written as follows:

 <?php echo ('<form action="'.$_SERVER["PHP_SELF"].'" method="GET">'); echo (' <label>Username:<input type="text" name="username" size="10" maxlength="30" /></label> <br> <label>Password:<input type="text" name="password" size="10" maxlength="30" /></label> <input type="submit" value="Submit"> </form>'); ?> 


Solution to Question 10-3

In order to also display the username and password upon submission, specify:

 <?php //Get the username and passowrd from the GET global array $username = $_GET["username"]; $password = $_GET["password"]; //determine if this is after the form's been submitted if (!empty($username)){   //display the values from the submission   echo ("Username: $username<br>");   echo ("Password: $password<br>"); } else { //display the form echo ('<form action="'.$_SERVER["PHP_SELF"].'" method="GET">'); echo (' <label>Username:<input type="text" name="username" size="10" maxlength="30" /></label> <br> <label>Password:<input type="text" name="password" size="10" maxlength="30" /></label> <input type="submit" value="Submit"> </form>'); } ?> 


Solution to Question 10-4

To select only author names starting with an "A", use the following query:

 SELECT * FROM authors WHERE author LIKE 'A%'` 



Learning PHP and MySQL
Learning PHP and MySQL
ISBN: 0596101104
EAN: 2147483647
Year: N/A
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net