PHP Questions & Answers – Updating and Deleting Entries

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Updating and Deleting Entries”.

1. When you are building administrative links you’ll need to accept two arguments, which of the following are they?
a) URL of previous entry and URL of the entry you are working with
b) The current page and previous page
c) URL of previous entry and previous page
d) The current page and URL of the entry you are working with
View Answer

Answer: d
Explanation: Your function should look like this:

  1. function adminLinks($page, $url)
  2. {
  3.   //Build admin links here
  4. }

2. Once your application can generate administrative links, you need to load those links into _________
a) php.ini
b) index.ini
c) index.php
d) start.php
View Ansewr

Answer: c
Explanation: You place your administrative links only on the full display of an entry, so you must place the call to load information from adminLinks() within a conditional statement

3. The URLs in the administrative links won’t mean anything to admin.php unless you modify _________
a) .htaccess
b) .adminaccess
c) .htmlaccess
d) .urlaccess
View answer

Answer: a
Explanation: You need to modify .htaccess with an additional rule that handles URLs passed in a link to admin.php.

4. The (|/) tells the server to match ___________
a) nothing
b) forward slash
c) backward slash
d) either nothing or a forward slash
View Answer

Answer: d
Explanation: The vertical pipe character (|) is the regular expression equivalent of “or”.
Note: Join free Sanfoundry classes at Telegram or Youtube

5. ([\w-]+) will match ___________
a) one word characters
b) one or more word characters
c) one or more word characters and/or hyphens
d) one or more word characters and hyphens
View Answer

Answer: c
Explanation: ([\w-]+), will match one or more word characters and/or hyphens—which is what your custom entry URLs consist.

6. You need to check whether ______ is set, to determine whether you’re editing an entry or creating a new one.
a) $_GET[‘url’]
b) $_SET[‘url’]
c) $_GET[‘admin’]
d) $_SET[‘admin’]
View Answer

Answer: a
Explanation: If an entry is being edited, you need to load the existing entry data and save each piece in a variable.

7. To identify entries marked for deletion, you check whether $_GET[‘page’] == ‘delete’ inside __________
a) index.php
b) index.ini
c) admin.php
d) .htaccess
View Answer

Answer: c
Explanation: In admin.php, you check whether $_GET[‘page’] == ‘delete’, then pass the entry URL to be deleted to a function.

8. To declare the function to confirm the deletion you need to add the code to __________
a) inc.php
c) include.php
d) functions.include.php
View Answer

Answer: b
Explanation: You need to add the following code –

  1. function confirmDelete($db, $url)
  2. {
  3.     $e = retrieveEntries($db, '', $url);
  4.     return <<<FORM
  5.     <form action="/simple_blog/admin.php" method="post">
  6.     <fieldset>
  7.     <legend>Are You Sure?</legend>
  8.     <p>Are you sure you want to delete the entry "$e[title]"?</p>
  9.     <input type="submit" name="submit" value="Yes" />
  10.     <input type="submit" name="submit" value="No" />
  11.     <input type="hidden" name="action" value="delete" />
  12.     <input type="hidden" name="url" value="$url" />
  13.     </fieldset>
  14.     </form>
  15.     FORM;
  16. }

9. Your confirmation form submits your choice, via the _______ method, to ________
a) GET index.php
b) GET admin.php
c) POST index.php
d) POST admin.php
View Answer

Answer: d
Explanation: To process this, you need to add an additional block of code to the top of admin.php that determines what choices you’ve made and act accordingly.

10. When a user confirms that he wishes to delete an entry, that entry’s URL is passed to a function which removes the entry from the __________
a) index.php
c) database
d) admin.php
View Answer

Answer: c
Explanation: If the function is successful, you send the user to the main page. If it fails, you stop the execution of the script and display an error, letting the user know that something went wrong.

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.