PHP Questions & Answers – HTML Forms

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “HTML Forms”.

1. Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET
View Answer

Answer: b
Explanation: The global variables $_GET is used to collect form data after submitting an HTML form with the method=”get”. The variable $_SET is also used to retrieve information from forms.

2. The attack which involves the insertion of malicious code into a page frequented by other users is known as _______________
a) basic sql injection
b) advanced sql injection
c) cross-site scripting
d) scripting
View Answer

Answer: c
Explanation: The cross-site scripting attack is among one of the top five security attacks carried out across the Internet. It is also known as XSS, this attack is a type of code injection attack which is made possible by incorrectly validating user data, which usually gets inserted into the page through a web form or using an altered hyperlink.

3. When you use the $_GET variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few
View Answer

Answer: c
Explanation: The information sent from a form with the method GET is visible to everyone i.e. all variable names and values are displayed in the URL.
advertisement
advertisement

4. When you use the $_POST variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few
View Answer

Answer: b
Explanation: The information sent from a form with the method POST is invisible to others i.e. all names/values are embedded within the body of the HTTP request.

5. Which variable is used to collect form data sent with both the GET and POST methods?
a) $BOTH
b) $_BOTH
c) $REQUEST
d) $_REQUEST
View Answer

Answer: d
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an HTML form.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which one of the following should not be used while sending passwords or other sensitive information?
a) GET
b) POST
c) REQUEST
d) NEXT
View Answer

Answer: a
Explanation: The information sent from a form with the method GET is visible to everyone i.e. all variable names and values are displayed in the URL. So, it should not be used while sending passwords or other sensitive information.

7. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()
View Answer

Answer: b
Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags.
advertisement

8. What will be the value of the variable $input in the following PHP code?

  1.     <?php
  2.     $input = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";
  3.     $input = strip_tags($input,"<i></i>");
  4.     echo $input;
  5.     ?>

a) Swapna Lawrence you are really pretty!
b) Swapna <td>Lawrence</td> you are really<i>pretty</i>!
c) Swapna <td>Lawrence</td> you are really pretty!
d) Swapna Lawrence you are really<i>pretty</i>!
View Answer

Answer: d
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially wreak havoc on a page.
advertisement

9. To validate an email address, which flag is to be passed to the function filter_var()?
a) FILTER_VALIDATE_EMAIL
b) FILTER_VALIDATE_MAIL
c) VALIDATE_EMAIL
d) VALIDATE_MAIL
View Answer

Answer: a
Explanation: The FILTER_VALIDATE_EMAIL is used to validates an e-mail address.

10. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?
a) 5
b) 6
c) 7
d) 8
View Answer

Answer: c
Explanation: There are seven validation filters. They are FILTER_VALIDATE_EMAIL, FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, FILTER_VALIDATE_REGEXP, FILTER_VALIDATE_URL.

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]

advertisement
advertisement
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.