Lab Assignment – IV (PHP)

  1. Write a simple PHP script that prints "Hello, PHP!" to the browser • Code

  2. Declare variables of different data types (integer, float, string) and demonstrate the usage of constants in PHP • Code

  3. Create a PHP program that uses if-else statements to check if a number is positive, negative, or zero. Utilize different operators for comparison • Code

  4. Develop a function that calculates the average of an array of numbers. Test the function with various arrays • Code

  5. Define a PHP class representing a "Book" with properties like title and author. Create objects of this class and display their attributes. • Code

  6. Design a simple HTML form with input fields. Create a PHP script that retrieves and displays the form data when submitted. • Code

  7. Enhance the previous form with PHP validation. Ensure that required fields are filled, and validate email addresses and make sure the phone number starts with 98 or 97 using regex • Code

  8. Implement PHP code that responds to a button click event on a form. Display a message when the button is clicked • Code

  9. Create a PHP script that sets a cookie with user preferences.Retrieve and display this information on subsequent visits • Code

  10. Build a form with various elements (textboxes, checkboxes, radio buttons). Use PHP to access and display the selected values • Code

  11. Develop a PHP script that reads content from a text file, modifies it, and then writes the updated content back to the file • Code

Lab 4.1 Connecting to database

  1. Write PHP code to establish a connection to a MySQL database, including the necessary credentials • Code

  2. Develop a PHP script to insert a new record into a MySQL database table.Ensure proper validation and sanitation of input data • Code

  3. Create a PHP script that retrieves and displays all records from a MySQL database table • Code

  4. Modify a specific record in a MySQL table using PHP. Ensure that the update is based on user input or specific criteria • Code

  5. Implement PHP code to delete a record from a MySQL table. Provide options for the user to select the record to be delete • Code

Last updated