PHP Closed Notes Quiz

1. What does PHP stand for?

Personal Home Page
Private Home Page
PHP: Hypertext Preprocessor
Personal Hypertext Processor

2. PHP server scripts are surrounded by which of the following delimiters>

<?php ?>
<&> </&>
<script> </script>
<?php> </?>

3. How do you write out "Hello World" in a dynamic page within the PHP directive?

Document.Write("Hello World");
"Hello World";
echo "Hello World";
System.out.println("Hello World");

4. The PHP syntax is most similar to:

ActionScript
C
JavaScript
VBScript

5. How can you recognize a PHP pre-defined function in working PHP code:

By name and parameters within parentheses: strpos($a, 'X')
By name and parameters within square brakets: strpos[$a, 'X']
By a dollar sign ($) in the name and parentheses: $strpos(a, 'X')
By a dollar sign ($) in the name and square brackets: $strpos[a, 'X']

6. Which is a valid way to get information into PHP variables from a form that was submitted using the "get" method?

$_GET[];
$_POST[];
$_REQUEST.QueryString();
$_REQUEST.FormData();

7. In PHP you can use both single quotes ( ' ' ) and double quotes ( " " ) to generate strings:

Never
Sometimes
Always
Depends on Server software

8. Which is the statement that is most true:

Include files must have the file extension ".inc".
Include files can have the file extension ".inc".
Include files must have the file extension ".php".
Include files cannot have either ".inc" or ".php" as a file extension.

9. What is a valid way to include PHP code in a file by filename?

<!--include file="time.inc"-->
<?php include("time.inc"); ?>
<% require file="time.inc" %>
<?php require_file("time.inc"); ?>

Bonus: When is including or requiring a file faster than the other?

10. What is the correct way to define your own function in PHP?

new_function myFunction() {}
function myFunction() {}
create myFunction() {}
myFunction function() {}

11. What is the correct way to open the file "time.txt" as readable but not writable?

open("time.txt");
fopen("time.txt","r");
fopen("time.txt","r-");
open("time.txt","read");

12. What is the correct way to connect to localhost when using a MySQL database?

mysql_connect("localhost");
dbopen("localhost");
connect_mysql("localhost");
mysql_open("localhost");

13. What is a valid way to add 1 to the $count variable in PHP code?

$count++;
$count=+1;
++count;
count++;

14. Which one of these variables has an illegal name?

$myVar
$my_Var
$my-Var
$myVariableName

15. Best Class Question:



THANKS FOR PLAYING!"; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); //select - use this database mysql_select_db($dbname); $query = "INSERT INTO Quiz VALUES ('".$_POST['q1']."','".$_POST['q2']."','".$_POST['q3']."','".$_POST['q4']."','".$_POST['q5']."','".$_POST['q6']."','".$_POST['q7']."','".$_POST['q8']."','".$_POST['q9']."','".$_POST['q10']."','".$_POST['q11']."','".$_POST['q12']."','".$_POST['q13']."','".$_POST['q14']."','".$_POST['q15']."')"; //echo 'Running Query: '.$query.'

'; $result = mysql_query($query); //echo 'RESULT ->'.$result.'<-'; //echo "Error message = ".mysql_error(); $query = "SELECT * from Quiz"; //echo 'Running Query: '.$query; $result = mysql_query($query); if($result) { echo ""; while($row = mysql_fetch_array($result)){ echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo "
'; echo $row['q1']; echo ''; echo $row['q2']; echo ''; echo $row['q3']; echo ''; echo $row['q4']; echo ''; echo $row['q5']; echo ''; echo $row['q6']; echo ''; echo $row['q7']; echo ''; echo $row['q8']; echo ''; echo $row['q9']; echo ''; echo $row['q10']; echo ''; echo $row['q11']; echo ''; echo $row['q12']; echo ''; echo $row['q13']; echo ''; echo $row['q14']; echo ''; echo $row['q15']; echo ''; echo $row['comments']; echo '
"; } } ?> -- -- Table structure for table `Quiz` -- CREATE TABLE IF NOT EXISTS `Quiz` ( `q1` text, `q2` text, `q3` text, `q4` text, `q5` text, `q6` text, `q7` text, `q8` text, `q9` text, `q10` text, `q11` text, `q12` text, `q13` text, `q14` text, `q15` text ); -- -- Dumping data for table `Quiz` -- INSERT INTO `Quiz` (`q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`, `q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`) VALUES ('d', 'd', 'c', '', 'd', 'a', 'b', 'c', 'b', 'c', 'a', 'a', 'a', 'c', ''), ('c', 'a', 'c', 'a', 'c', 'a', 'b', 'c', 'b', 'd', 'd', 'a', 'a', 'c', ''), ('c', 'a', 'c', 'c', 'a', 'a', 'c', 'c', 'b', 'b', 'b', 'a', 'a', 'c', ''), ('c', 'a', 'c', 'a', 'c', 'a', 'b', 'c', 'b', 'd', 'd', 'a', 'a', 'c', ''), ('c', 'a', 'c', 'a', 'c', 'a', 'b', 'c', 'b', 'd', 'd', 'a', 'a', 'c', ''), ('c', 'a', 'c', 'd', 'd', 'a', 'c', 'b', 'b', 'c', 'b', 'a', 'a', 'c', ''), ('c', 'a', 'c', 'b', 'a', 'a', 'b', 'c', 'b', 'b', 'b', 'a', 'b', 'a', ''), ('d', 'a', 'c', 'c', 'c', 'a', 'b', 'b', 'b', 'b', 'b', 'a', 'b', 'c', 'When would you use a value of "submitted" on a form?'), ('b', 'a', 'c', 'c', 'a', 'c', 'c', 'b', 'd', 'b', 'b', 'a', 'a', 'c', ''), ('d', 'd', 'c', 'c', 'a', 'a', 'c', 'c', 'b', 'b', 'b', 'a', 'a', 'c', 'Object Oriented PHP - What is it, how does one use it'), ('c', 'a', 'c', 'c', 'b', 'b', 'a', 'c', 'b', 'd', 'b', 'a', 'a', 'c', ''), ('d', 'a', 'c', 'a', 'a', 'a', 'b', 'b', 'b', 'a', 'd', 'a', 'a', 'c', ''), ('d', 'a', 'c', 'c', 'c', 'a', 'b', 'b', 'b', 'b', 'b', 'a', 'b', 'c', 'When would you use a value of "submitted" on a form?'), ('c', 'a', 'c', 'c', 'a', 'a', 'c', 'c', 'b', 'b', 'b', 'a', 'a', 'c', '');