Complete PHP Exam Paper (Theory + Practical)

👇


📝 Full PHP Exam Paper

Subject: PHP Programming
Time: 3 Hours
Maximum Marks: 100


📘 Section A – Objective (MCQs)

(10 × 1 = 10 Marks)

  1. PHP stands for:
    A) Personal Home Page
    B) Hypertext Preprocessor
    C) Private Home Page
    D) Preprocessor Home Page
    ✅ Answer: B
  2. Which symbol is used for variables in PHP?
    A) #
    B) $
    C) @
    D) &
    ✅ Answer: B
  3. Which function outputs text?
    A) print()
    B) echo()
    C) Both
    D) None
    ✅ Answer: C
  4. Which error stops execution?
    A) Warning
    B) Notice
    C) Fatal Error
    D) Info
    ✅ Answer: C
  5. Which superglobal is used for form data?
    A) $_FORM
    B) $_POST
    C) $_DATA
    D) $_INPUT
    ✅ Answer: B
  6. Which function connects to MySQL (procedural)?
    A) connect_db()
    B) mysqli_connect()
    C) db_connect()
    D) mysql_link()
    ✅ Answer: B
  7. What does isset() check?
    A) Empty value
    B) Variable exists
    C) Data type
    D) Output
    ✅ Answer: B
  8. Which keyword is used for exception?
    A) catch
    B) throw
    C) try
    D) All
    ✅ Answer: D
  9. Which function is used for sessions?
    A) session_create()
    B) session_start()
    C) session_open()
    D) start_session()
    ✅ Answer: B
  10. Default file extension of PHP?
    A) .html
    B) .js
    C) .php
    D) .xml
    ✅ Answer: C

📗 Section B – Short Answer

(10 × 2 = 20 Marks)

  1. What is PHP?
  2. Difference between GET and POST
  3. What is a session?
  4. What is a cookie?
  5. Define array in PHP
  6. What is error handling?
  7. What is include vs require?
  8. What is a function?
  9. What is $_SERVER?
  10. What is PDO?

📙 Section C – Long Answer

(5 × 6 = 30 Marks)

  1. Explain PHP data types with examples
  2. Explain loops in PHP (for, while, foreach)
  3. Explain form handling with example
  4. Explain error handling in PHP
  5. Explain session and cookie with examples

💻 Section D – Practical / Coding

(4 × 10 = 40 Marks)


✅ Q1. Write a PHP program to check even or odd number.

<?php
$num = 10;if ($num % 2 == 0) {
echo "Even Number";
} else {
echo "Odd Number";
}
?>

✅ Q2. Create a form and display submitted data.

<form method="post">
Name: <input type="text" name="name">
<input type="submit">
</form><?php
if ($_POST) {
echo "Name: " . $_POST['name'];
}
?>

✅ Q3. Connect to MySQL database.

<?php
$conn = mysqli_connect("localhost", "root", "", "test");if (!$conn) {
die("Connection failed");
}
echo "Connected successfully";
?>

✅ Q4. Exception Handling Example

<?php
try {
if (!file_exists("test.txt")) {
throw new Exception("File not found");
}
} catch (Exception $e) {
echo $e->getMessage();
}
?>

🏆 Bonus Question (Optional – 10 Marks)

Create a login system using:

  • Form
  • Session
  • Validation

📊 Marking Scheme

SectionMarks
A10
B20
C30
D40
Bonus10

🎯 Examiner Tips

  • Write clean syntax
  • Use comments in code
  • Handle errors properly
  • Show output clearly
  • Follow best practices