INTRODUCTION TO WEB PROGRAMMING -
SAMPLE EXAM WITH ANSWERS
SECTION A: THEORY QUESTIONS AND ANSWERS
1. Define web programming and explain its main components.
Web programming is the process of developing web applications and websites that run on the
internet. It involves creating, coding, and maintaining both the frontend (what users see) and
backend (how data is processed). Components include: Frontend (HTML, CSS, JavaScript),
Backend (PHP, Python, Node.js), and Database (MySQL, MongoDB).
2. Differentiate between client-side and server-side scripting.
Client-side scripting runs in the user’s browser (e.g., JavaScript) while server-side scripting runs on
the server (e.g., PHP, Python). Client-side handles interface and interactivity; server-side handles
logic and data processing.
3. Explain the role of HTML, CSS, and JavaScript in web development.
HTML defines structure, CSS adds style, and JavaScript adds interactivity to web pages.
4. Describe how the client-server model works.
A user requests a resource through a browser; the request goes to a web server, which processes
it (possibly using a database) and sends a response back to the browser for display.
5. What are the advantages of using CSS frameworks like Bootstrap?
They enable faster development, provide responsive design, ensure consistent styling, and offer
cross-browser compatibility.
SECTION B: PRACTICAL / CODING QUESTIONS AND ANSWERS
1. Create a simple HTML page with a form to collect a user’s name and email.
<!DOCTYPE html> <html> <head><title>User Form</title></head> <body> <h2>Registration
Form</h2> <form action='submit.php' method='post'> Name: <input type='text'
name='username' required><br><br> Email: <input type='email' name='email'
required><br><br> <input type='submit' value='Submit'> </form> </body> </html>
2. Write CSS code to style a navigation bar with hover effects.
nav { background-color: black; padding: 10px; } nav a { color: white; margin: 10px;
text-decoration: none; } nav a:hover { color: yellow; }
3. Use JavaScript to validate a form before submission.
<script> function validateForm() { let name =
document.forms['myForm']['username'].value; if (name == '') { alert('Name must be
filled out'); return false; } } </script> <form name='myForm' onsubmit='return
validateForm()'> <input type='text' name='username'> <input type='submit'
value='Submit'> </form>
4. Develop a simple PHP script that saves form data into a database.
<?php $conn = mysqli_connect('localhost', 'root', '', 'webdb'); $name =
$_POST['username']; $email = $_POST['email']; $sql = "INSERT INTO users (name,
email) VALUES ('$name', '$email')"; if (mysqli_query($conn, $sql)) { echo 'Record
saved successfully!'; } else { echo 'Error: ' . mysqli_error($conn); }
mysqli_close($conn); ?>
5. Write an HTML document that uses an external CSS file for styling.
<!DOCTYPE html> <html> <head> <link rel='stylesheet' href='style.css'> <title>My Web
Page</title> </head> <body> <h1>Welcome to My Page</h1> <p>This page is styled using
an external CSS file.</p> </body> </html>
SECTION C: MULTIPLE CHOICE ANSWERS
1. Which tag is used to insert an image in HTML? a) <img>
2. CSS stands for: b) Cascading Style Sheets