PHP Assignments
PHP Assignments
• Write a PHP script that defines a range of numbers using two variables, $start
and $end, which represent the starting and ending values of the range,
respectively.
• Use a for loop to iterate through each number within this range. Inside the loop,
use an if statement to determine whether the current number is even or odd by
checking if the number modulo 2 is equal to 0.
• If the number is even, print a message indicating that the number is even;
otherwise, print a message indicating that the number is odd.
(For example, if $start is set to 1 and $end is set to 10, the script should print whether
each number from 1 to 10 is even or odd.)
Assignment 2
Create a simple PHP script integrated with HTML that processes form data and
generates dynamic content based on user input.
1. Create an HTML form that asks for the user's name and age. The form should
use the POST method to submit the data.
2. Use PHP to process the submitted form data in the same file.
3. If both name and age are provided, sanitize the input to prevent XSS attacks
and cast the age to an integer.
4. Display a personalized greeting with the user's name and age.
5. Based on the age, display whether the user is a minor or an adult.
Assignment 3
Create a web page that dynamically generates a multiplication table (from 1 to 10)
using PHP.
<style>
table {
border-collapse: collapse;
width: 50%;
margin: 20px auto;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
</style>
3. Use PHP embedded within the HTML to create the multiplication table.
4. Use nested loops in PHP to generate the rows and columns of the table.
5. Ensure the first row and column of the table contain the numbers 1 to 10, and
the cells display the product of the corresponding row and column numbers.