PHP Exam1 Questions and Correct
Answers
Explain what previd is (line 16), how it gets created and what it contains. - $id=$_GET['previd'] - Answer-
PrevId is a URL parameter
It was attached to a URL as part of an anchor tag on a previous page that we don't have
It is used to pass the ID number of the product that is selected by the user on the produced page using
the GET method
When the user clicks on the anchor, the ID number is captured by this parameter and passed to this
current page (nicepage.php)
hometeq.com/prevId=123
Describe what happens to previd and $id if the user the selects the 'Cookie Jar' in the pro table
presented on the "Sample Data and PHP Code" document. - Answer-When the user clicks on the cookie
jar *anchor*, the value of the id for this product 6211 gets appended to the url as previd
This makes use of the GET method to pass a value (6211) by URL
When using this method a *superglobal variable*
, $_GET('prevId') gets created to capture the value
The value (6211) then gets assigned to a local variable called $id for greater convenience.
This local variable is then used as part of a query in line 18 to retrieve all the details of this specific
product (ie. the cookie jar)
Explain what $SQL is (line 18), how it gets created and what value it contains.
$SQL = "select * from pro where prId=".$id; - Answer-$SQL is a local variable of type string
It gets assigned a SQL query
This SQL query retrieves all the details from the pro table for which the id of the product matches the
value of the id selected by the user
This value is currently stored in the local variable $id and was passed from the previous page using the
GET method
This SQL query is executed on line 19 using the mysqli_query function
Explain what $runSQL is (line 19), how it gets created and what value it contains.
$runSQL = mysqli_query($conn,$SQL) or die(mysqli_error($conn)); - Answer-The $runsql is a variable of
type boolean
It gets assigned the outcome of the execution of the SQL query or an error
Answers
Explain what previd is (line 16), how it gets created and what it contains. - $id=$_GET['previd'] - Answer-
PrevId is a URL parameter
It was attached to a URL as part of an anchor tag on a previous page that we don't have
It is used to pass the ID number of the product that is selected by the user on the produced page using
the GET method
When the user clicks on the anchor, the ID number is captured by this parameter and passed to this
current page (nicepage.php)
hometeq.com/prevId=123
Describe what happens to previd and $id if the user the selects the 'Cookie Jar' in the pro table
presented on the "Sample Data and PHP Code" document. - Answer-When the user clicks on the cookie
jar *anchor*, the value of the id for this product 6211 gets appended to the url as previd
This makes use of the GET method to pass a value (6211) by URL
When using this method a *superglobal variable*
, $_GET('prevId') gets created to capture the value
The value (6211) then gets assigned to a local variable called $id for greater convenience.
This local variable is then used as part of a query in line 18 to retrieve all the details of this specific
product (ie. the cookie jar)
Explain what $SQL is (line 18), how it gets created and what value it contains.
$SQL = "select * from pro where prId=".$id; - Answer-$SQL is a local variable of type string
It gets assigned a SQL query
This SQL query retrieves all the details from the pro table for which the id of the product matches the
value of the id selected by the user
This value is currently stored in the local variable $id and was passed from the previous page using the
GET method
This SQL query is executed on line 19 using the mysqli_query function
Explain what $runSQL is (line 19), how it gets created and what value it contains.
$runSQL = mysqli_query($conn,$SQL) or die(mysqli_error($conn)); - Answer-The $runsql is a variable of
type boolean
It gets assigned the outcome of the execution of the SQL query or an error