ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
13 marks · Sessions
Competitors register using a sign-up form on the page signup.html. The form data is then submitted to the PHP page confirmation.php. The layout produced by the page confirmation.php is shown in the wireframe design below. use details submitted on signup.html Jedburgh Jigsaw Competition babJones@mymail.com thanks for your enquiry Dear Barbara You are registering for the 2025 Jedburgh Jigsaw Competition. click to confirm registration activate page saveDetails.php to save competitor’s details to database Please click below to confirm your registration. Explain how sessions and session variables would be used in this situation. Before the form data can be processed, the website must first connect to the database server. Write the PHP code needed to connect to the database and assign the connection to the variable $link. Your code should make appropriate use of the following connection details: database: jigsawFixture password: pass1234 server: jigsaw1 user: admin The competition consists of two rounds. In each round, the time taken to complete the jigsaw is recorded. At the end of each round, points are awarded to the competitors who completed the jigsaw in the fastest times as follows: • The competitor with the best time receives 8 points. • The competitor with the next best time receives 5 points. • The competitor with the third best time receives 3 points. • The competitors with the next 21 best times receive 1 point. • The remaining competitors do not receive any points. It can be assumed that all times are unique. The section of the code used to process the results of Round 1 is shown below. … Line 37 $query = "SELECT competitorID, forename, surname, timeTakenRound1 FROM Competitor ORDER BY timeTakenRound1 ASC"; Line 38 $round1 = mysqli_query($link, $query); Line 39 echo "<p>Scores for Round 1</p>"; Line 40 echo "<table>"; Line 41 //display headings of HTML table for Round 1 results Line 42 … Line 43 //initialise $numProcessed to count number of competitors processed Line 44 $numProcessed = 0; Line 45 //initialise points allocated to a competitor Line 46 $points = 0; Line 47 //process round 1 results of an individual competitor Line 48 while (($row = mysqli_fetch_array($round1)) and $numProcessed < 24) Line 49 { Line 50 //allocate points to an individual competitor … Line 62 //display individual competitor details in table Line 63 __________________ Line 64 //execute query to store the competitor's points in the database Line 65 __________________ Line 66 $numProcessed = $numProcessed + 1; Line 67 } Line 68 echo "</table>"; Explain the significance of the SQL query at line 37. Explain how the complex condition at line 48 is used to control the while loop. Within the while loop, the points allocated to the competitors with the best times are used to update the variable $points. Using pseudocode, design the section of code used to allocate points to the competitors. The screen shot below shows the output produced by the HTML table used to display the Round 1 Results. Round 1 Results Competitor Time Taken Points Barbara Jones 02:32:24 8 Olive Oil 02:38:38 5 David Defau 02:39:58 3 Andy Peters 02:40:30 1 Lin Cadiz 02:41:19 1 Write the PHP code needed at line 63 to display the details of a single competitor in one row of the HTML table. Once the points for an individual competitor have been allocated and displayed, a query is used to store the points in the database. The incomplete code used at line 65 is shown below. mysqli_query($link, "_______________________________ WHERE competitorID = '$row[competitorID]'"); Write the statement needed to complete this query. The Jedburgh Jigsaw Competition is held each year. Jigsaw enthusiasts can register to take part in the competition and view the results on the competition website. Data about each competitor is stored in an online database in a table called Competitor. The structure of the Competitor table is shown below: Competitor competitorID forename surname email timeTakenRound1 timeTakenRound2 competitorPoints
• session variables allow values stored in variables to persist across several pages of the website. In this situation, session variables are needed to store the details submitted by a competitor that they can shared across several pages of the website so that the details can be stored in the database using code on the saveDetails.php page • values submitted by the user on page signup.html are POSTed to confirmation.php. A session must be started on the confirmation.php page to initialise the session variables using the submitted values • A session will also be needed on the saveDetails.php page to ensure that the values contained in the session variables are available and can be accessed by the code used to save the competitor’s details to the database Award 1 mark each for any 3 of the following: • description of need use made of session variables to share data across several pages of a website • need for a session on the page confirmation.php to initialise session variables • use made of submitted values to initialise the session variables • need for a session on the saveDetails.php so that can values stored in the session variables can be accessed Maximum 3 marks See sample solution below. Award 1 mark for correct assignment use of details provided in the question. This may be indicated as separate assignment statements or as parameter values of the mysqli_connect() function. Award 1 mark for correct use of mysqli_connect() function in connection code with the 4 correct parameters or assignment details in the correct sequence. $server = "jigsaw1"; $username = "admin"; $password = "pass1234"; $database = "jigsawFixtures"; $link = mysqli_connect($server,$username,$password,$database); An ascending sort is used to arrange the competitor details from shortest to longest time taken to complete the round 1 jigsaw puzzle. This is needed to ensure that the best 24 times are listed first. Award 1 mark for explanation of importance of ascending sort. • the mysqli_fetch_array() function is used to allocate a single set of results returned by the query to the $row variable and will terminate the loop when there are no more results to be processed • the $numProcessed variable is incremented at the end of each iteration and will terminate the loop once the first 24 sets of competitor details have been processed Award 1 mark for explanation of how mysqli_fetch_array() function is used to terminate the loop. Award 1 mark for explanation of how $numProcessed is used to terminate the loop. 1. if $numProcessed = 0 then 2. set $points = 8 3. elseif ($numProcessed = 1) 4. set $points = 5 5. elseif ($numProcessed = 2) 6. set $points = 3 7. else 8. set $points = 1 9. end if Award 1 mark for use of $numProcessed variable to make comparison. Award 1 mark for updating points correctly. See sample solution below. Award 1 mark for use of echo with forename, surname, timeTakenRound1 and $points. Award 1 mark for correct use of <tr>, </tr>, <td> and </td> Note: do not penalise for incorrect or missing $row, ' or " echo '<tr><td>'.$row['forename'].'</td>'." ". '<td>'.$row['surname']. '</td><td>'.$row['timeTakenRound1']. '</td><td>'.$points.'</td></tr>'; See sample solution below. Note: do not penalise for missing inverted commas. UPDATE Competitor SET competitorPoints = '$points'