1. How does PHP receive form data sent via the GET method?
Answer:
Explanation:
PHP receives data sent via the GET method through the global $_GET array.
2. What method should be used to send sensitive data, like passwords, in a PHP form?
Answer:
Explanation:
The POST method should be used for sending sensitive data, as it does not expose data in the URL.
3. How do you retrieve a form input value in PHP if the method is POST?
Answer:
Explanation:
Form data sent via POST is accessed in PHP using the $_POST array with the name of the input.
4. What is the purpose of the htmlspecialchars function in form handling in PHP?
Answer:
Explanation:
htmlspecialchars() converts special characters to HTML entities, helping prevent XSS attacks.
5. Which superglobal array in PHP contains information about both GET and POST data?
Answer:
Explanation:
The $_REQUEST array contains data from both $_GET and $_POST as well as cookies.
6. How do you check if a form has been submitted in PHP?
Answer:
Explanation:
Form submission can be checked using several methods, including checking the request method, if data arrays are not empty, or if the submit button is set.
7. What attribute must be included in an HTML form to upload files to a PHP script?
Answer:
Explanation:
The enctype attribute must be set to "multipart/form-data" for uploading files through a form.
8. How are file uploads accessed in PHP?
Answer:
Explanation:
Uploaded files in PHP are accessed using the $_FILES superglobal array.
9. How do you access a checkbox value in PHP if it is checked?
Answer:
Explanation:
To access a checkbox value, you need to check if it is set using isset() since unchecked boxes are not sent in the request.
10. Which method, GET or POST, appends form data to the URL?
Answer:
Explanation:
The GET method appends form data to the URL, while POST sends data in the request body.
11. How do you ensure a form field is not empty in PHP?
Answer:
Explanation:
To ensure a form field is not empty, check that it is set and its value is not an empty string.
12. Which PHP function is used to validate email addresses?
Answer:
Explanation:
The filter_var() function with the FILTER_VALIDATE_EMAIL filter is used to validate email addresses.
13. How do you retain form field values after submission in PHP?
Answer:
Explanation:
To retain form field values, echo the submitted values in the value attribute of the form fields.
14. What is the default form submission method in HTML?
Answer:
Explanation:
If the method attribute is not specified in an HTML form, the default submission method is GET.
15. How do you access form data sent via both GET and POST methods in PHP without knowing the method used?
Answer:
Explanation:
The $_REQUEST superglobal array can be used to access form data regardless of whether the GET or POST method was used.
Comments
Post a Comment