Computer

PHP/Oracle Development


Syllabus
Schedule
Reading
Discussion
Project
Test
Resource
Tip

Review Questions: Week 5
(Functions)

  1. What is the output from the following file_inclusion;php code?

    The following two files are saved in your Document Root directory.

    -----variables.php---------

    <?php
    $product='Oracle';
    $field='database';
    ?>

    -----file_inclusion.php -------

    <?php
    include 'variables.php';
    echo "The output after \"include\" function is <br>";
    echo "An $product $field <br>";
    ?>





  2. In the following PHP code, a call for the function is missing. What is the correct statement to call the function?

    <?php
    //Define the variables for PHP program
    $username='Brenda';
    $password='bikeforfun';
    //call the function "ping_function"

    //The following defines the function "ping-function".

    function ping_function ($user,$pwd)
    {
    print "[User Name]:  &nbsp&nbsp ".$user."<br/>";
    print "[Password]:  &nbsp&nbsp ".$pwd."<br/>";
    }
    ?>



  3. What is the output from the following PHP code?

    <?php
    //Define the variables for PHP program
    $username='Brenda';
    $password='bikeforfun';

    //call the function "ping_function"

    ping_function('Mike','baseball');

    //The following defines the function "ping-function".

    function ping_function ($user,$pwd)
    {
    print "[User Name]: &nbsp&nbsp ".$user."<br/>";
    //print "[Password]: &nbsp&nbsp ".$pwd."<br/>";

    }

    ?>





  4. On the following HTML form, a user can see the password as he/she types in the password field. How do you hide the password so that others can not see your password when you type in?

    <html>
    <form name="myInputForm" action="php_action.php" method="post">
    User Name: <input type="text" name="username" /><br />
    Password: <input type="text" name="pwd" /><br />
    <input type="submit" value="Submit" /><br />
    </form> 
    </html>




  5. Code debuging:

    ------form.php------

    <html>
    <form name="myInputForm" action="php_action.php" method="post">
    User Name: <input type="text" name="username" /><br />
    Password: <input type="password" name="pwd" /><br />
    <input type="submit" value="Submit" /><br />
    </form> 
    </html>

    ----php_action.php----

    <?php
    //Get the values of the variables from the HTML form.
    $username=$_POST[username"];
    $password=$_POST["pwd"];

    //call the function "ping_function"
    ping_function($username, $password);

    //The following defines the function "ping-function".
    function ping_function ($user,$pwd)
    {
    print "[User Name]:  &nbsp&nbsp ".$user."<br/>";
    print "[Password]:  &nbsp&nbsp ".$pwd."<br/>";
    }
    ?>

    ---

    In the above program, there is one error within php_action.php. Provide a correct statement (complete) so that you can correct the syntax error.


     







  6. Debugging:

    ------form.php------

    <html>
    <form name="myInputForm" action="php_action.php" method="post">
    User Name: <input type="text" name="username" /><br />
    Password: <input type="password" name="pwd" /><br />
    <input type="submit" value="Submit" /><br />
    </form> 
    </html>

    ----php_action.php----

    <?php
    //Get the values of the variables from the HTML form.
    $username=$_POST["$username"];
    $password=$_POST["pwd"];

    //call the function "ping_function"
    ping_function($username, $password);

    //The following defines the function "ping-function".
    function ping_function ($user,$pwd)
    {
    print "[User Name]:  &nbsp&nbsp ".$user."<br/>";
    print "[Password]:  &nbsp&nbsp ".$pwd."<br/>";
    }
    ?>

    ---

    In the above program, there is one error within php_action.php. Provide a correct statement (complete) so that you can correct the syntax error.



  7. Debugging:

    ------form.php------

    <html>
    <form name="myInputForm" action="php_action.php" method="post">
    User Name: <input type="text" name="username" /><br />
    Password: <input type="password" name="pwd" /><br />
    <input type="submit" value="Submit" /><br />
    </form> 
    </html>

    ----php_action.php----

    <?php
    //Get the values of the variables from the HTML form.
    $username=$_POST["username"];
    $password=$_POST["password"];

    //call the function "ping_function"
    ping_function($username, $password);

    //The following defines the function "ping-function".
    function ping_function ($user,$pwd)
    {
    print "[User Name]:  &nbsp&nbsp ".$user."<br/>";
    print "[Password]:  &nbsp&nbsp ".$pwd."<br/>";
    }
    ?>

    ---

    In the above program, there is one error within php_action.php. Provide a correct statement (complete) so that you can correct the syntax error.



  8. What is the exact output of the LAST line from the following PHP code?

    <?php
    // Declare variable.
    $var = "Oracle";

    // Print actual parameter value before function.
    print "Before function \$var [".$var."]<br>";

    // Call the user-defined function.
    print_string($var);

    // Print actual parameter value after function.
    print "After function \$var [".$var."]";

    // Define function that prints an input parameter as a string.
    function print_string($var)
    {
    // Print the local variable with a text literal.
    $var = "Access";

    // Print actual parameter value.
    print "Inside function \$var [".$var."]<br>";
    }
    ?>



  9. What is the exact output of the LAST line from the following PHP code?

    <?php
    // Declare variable.
    $var = "Oracle";

    // Print actual parameter value before function.
    print "Before function \$var [".$var."]<br>";

    // Call the user-defined function.
    print_string($var);

    // Print actual parameter value after function.
    print "After function \$var [".$var."]";

    // Define function that prints an input parameter as a string.
    function print_string(&$var)
    {
    // Print the local variable with a text literal.
    $var = "Access";

    // Print actual parameter value.
    print "Inside function \$var [".$var."]<br>";
    }
    ?>