ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
15 marks · Creating and dropping tables
Details of user accounts are stored in a table called User with the attributes indicated below. Sample Data Attributes userName email password essdog shaun@myemail.com e22d0g Write SQL code to create the User table. For security reasons, users are encouraged to update their password on a regular basis. To update their password, a user must complete the HTML form shown below. Username New Password Re-enter password Update When the user submits the form, the data entered is transmitted securely to a server-side script called update.php. Write the HTML code to create this HTML form. A user updates her password with the details shown below. Username adasmith New Password ?43h56 Re-enter password ?43h56 Update Using a server-side scripting language with which you are familiar, write the script used to process these details. The script should: • assign the form details to server-side variables • display an error message when the two passwords do not match • only update details in the User table when the passwords match. You should assume that a valid connection already exists and is called $conn. A second table called Message is used to store the user messages. Some sample records from the Message table are shown below. date messageID comment userName media 309881 Great concert last night at Glasgow Barrowlands. 03/04/2018 adasmith 30981concert.jpg 309882 Beautiful sunny day in Dundee — again! 03/04/2018 kezzam 30982sky.jpg 309884 Who will win the match tonight? 04/04/2018 aliceb 309885 Heading home for tea! 05/04/2018 adasmith 309886 Disappointing result yesterday :( 05/04/2018 aliceb 30986score.jpg Write an SQL query to total the number of messages made by each user. The query should display the username and the total number of messages made. The terms and conditions of the social media website grant the company a non-exclusive, royalty-free license for all images that are uploaded by users. Describe one legal and one economic implication for users who share their own photographs on this website. A programmer decides to build a social media website. Users of the site will be able to post messages and attach media files.
CREATE TABLE User ( userName varchar(20) email varchar(30) password varchar(20) PRIMARY KEY(userName) ); 1 mark for creating table with correct fields and data types; text, char or varchar acceptable; any valid length acceptable. Do not accept string. NOTE: minimum acceptable fields sizes are 6, 17, 6. 1 mark for assigning primary key. <form action="update.php" method="post"> Username <input type = "text" name = "username"> <br> New Password <input type = "password" name = "password1"> <br> Re-enter Password <input type = "password" name = "password2"> <br> <input type= "submit" value="Update"> </form> 1 mark for form with correct action and method. 1 mark for 3 labels with 3 text fields (accept password type for both passwords). 1 mark for submit button with correct label. NOTE: Input type for password can be text or password. NOTE: button tag could be used as alternative for submit button <button type= "submit">Update </button> <?php $username = $_POST["userName"]; $pass1 = $_POST["password1"]; $pass2 = $_POST["password2"]; if ($pass1 != $pass2) { echo ("Error – Passwords do not match"); } else { $sql = "UPDATE User SET password = '$pass1' WHERE username = '$username'"; mysql_query($sql, $conn); }; ?> NOTE: accept also mysqli_query($sql, $conn); 1 mark for assigning POST values to variables (Note: if GET has been used in part (b), accept assigning GET values to variables). 1 mark for conditional statement used to compare pass1 with pass2 With appropriate error message. 1 mark for correct SET clause of UPDATE query. 1 mark for correct WHERE clause. 1 mark for execution of SQL query. NOTE: POST values should match HTML element names in part (b) above. NOTE: ignore sequence of SET and WHERE clauses. SELECT userName, COUNT(*) FROM Message GROUP BY userName; NOTE: any field can be used with the COUNT function. 1 mark for correct use of aggregate function. 1 mark for correct fields and table. 1 mark for correctly grouping by user name. Various answers are possible. For example: Legal Issue: By agreeing to the terms and conditions, users hand over the IPR (including copyright) of any images that they upload to the website. (1 mark) Economic Issue: Website users will lose potential income from photos used by the website company in publicity or marketing material. (1 mark) 1 mark for any appropriate legal issue. 1 mark for any appropriate economic issue. NOTE: issues must relate to website users and not the business.
Previous question: AH Computing Science 2018 Question 1 (CfE)