Web Programming Viva Questions & Answers
UNIT I – Internet, Web, and Browser Basics
1. What is the Internet?
The Internet is a global network connecting millions of computers for communication and data
exchange.
2. What is the World Wide Web (WWW)?
The WWW is a system of interlinked hypertext documents accessed through the Internet using web
browsers.
3. What are URLs?
URL stands for Uniform Resource Locator. It specifies the address of a resource on the web.
4. What is a Web Server?
A web server is software or hardware that stores, processes, and delivers web pages to clients.
5. What is a Web Browser?
A web browser is software used to access and view web pages, such as Chrome, Firefox, or Edge.
6. What is MIME?
MIME stands for Multipurpose Internet Mail Extensions. It indicates the type of content (e.g.,
text/html, image/png).
7. What is the Document Object Model (DOM)?
The DOM represents the structure of an HTML or XML document as a tree of objects that JavaScript
can manipulate.
8. What is an Event in JavaScript?
An event is an action or occurrence (like a click or keypress) that JavaScript can respond to.
9. What is the purpose of the navigator object?
The navigator object provides information about the browser and operating system.
10. What is Internet Security?
It refers to protecting online data and systems from unauthorized access, viruses, and cyber threats.
UNIT II – Dynamic JavaScript and XML
1. What is a dynamic document?
A document that changes its content or style without reloading the entire web page.
2. How can you move an element dynamically in JavaScript?
By changing its position properties such as style.left and style.top using scripts.
3. What is XML?
XML (eXtensible Markup Language) is used to store and transport data in a structured and readable
format.
4. What is the difference between HTML and XML?
HTML is for displaying data, while XML is for storing and transferring data.
5. What is a DTD in XML?
DTD (Document Type Definition) defines the structure and legal elements of an XML document.
6. What is an XML Schema?
An XML Schema defines the elements, attributes, and their data types in an XML document.
7. What is XSLT?
XSLT (Extensible Stylesheet Language Transformations) is used to transform XML data into other
formats like HTML.
8. What are Web Services?
Web services allow communication and data exchange between applications over the Internet using
XML-based protocols.
HTTP Methods: GET and POST
1. What is the difference between GET and POST methods in PHP?
GET sends data through the URL (visible in the address bar).
POST sends data through the HTTP request body (not visible in the URL).
GET is less secure and limited in data size, while POST is more secure and allows larger data.
2. When should you use GET?
Use GET when retrieving data that doesn’t modify server content — e.g., search queries, filters.
3. When should you use POST?
Use POST for submitting forms that change server data — e.g., registration, login, or database updates.
4. How do you access data sent by GET in PHP?
Using the superglobal array: $_GET['fieldname'].
5. How do you access data sent by POST in PHP?
Using the superglobal array: $_POST['fieldname'].
6. Can you use both GET and POST together?
Yes, but it’s generally not recommended for the same form. You can, however, use both in the same
page for different purposes.
7. What is the default method of an HTML form?
If no method is specified, the default is GET.
8. Which method is more secure for sensitive data like passwords?
POST is more secure because it doesn’t display data in the URL.
9. Can you bookmark a URL with POST data?
No, POST data is not stored in the URL, so it cannot be bookmarked.
10. What is the syntax for defining form method in HTML?
<form action="process.php" method="post">
HTML & JavaScript Basics
1. What is the difference between <div> and <span>?
<div> is a block-level element, while <span> is an inline element.
2. What is the purpose of the <form> tag?
It is used to collect user input that can be sent to a server.
3. What is the purpose of the action attribute in a form?
It defines the URL or PHP file where the form data will be submitted.
4. What is event handling in JavaScript?
Event handling allows a web page to respond to user actions like clicks, keypresses, or mouse
movements.
5. What are some common JavaScript events?
onclick, onload, onmouseover, onkeyup, onsubmit.
6. What is the DOM used for in JavaScript?
To manipulate HTML and CSS dynamically.
7. What is innerHTML in JavaScript?
It’s a property that allows you to get or set the HTML content of an element.
8. What is the use of parseInt() and parseFloat()?
They convert string values to integers and floating-point numbers, respectively.
9. How do you prevent a form from submitting in JavaScript?
By returning false in the onsubmit event or using event.preventDefault().
10. What is the difference between == and === in JavaScript?
== checks for equality after type conversion, while === checks for both value and data type.
PHP and Server-side Concepts
1. What are superglobal variables in PHP?
Built-in variables available in all scopes, like $_GET, $_POST, $_SESSION, $_COOKIE, $_FILES,
$_SERVER.
2. What is $_SERVER['PHP_SELF']?
It returns the filename of the currently executing script.
3. What is the purpose of isset() function?
Checks whether a variable is set and not NULL.
4. What is the difference between include() and require() in PHP?
Both include files, but require() produces a fatal error if the file is missing, while include() gives a
warning.
5. What is a session in PHP?
A session stores data on the server to track user activity across multiple pages.
6. How do you start a session in PHP?
Using session_start().
7. How do you destroy a session in PHP?
Using session_destroy().
8. What is the difference between cookies and sessions?
Cookies store data on the client side, sessions store data on the server side.
9. What is $GLOBALS array in PHP?
It stores all global variables accessible anywhere in the script.
10. What are magic constants in PHP?
Predefined constants that change depending on where they are used, e.g., __FILE__, __LINE__,
__DIR__.
File Handling and Database
1. How do you open a file in PHP?
Using fopen("filename.txt", "r").
2. What are common file modes in PHP?
r (read), w (write), a (append), r+ (read/write).
3. What function is used to read a file line by line?
fgets().
4. What is SQL Injection?
A security vulnerability where attackers inject malicious SQL queries via input fields.
5. How do you prevent SQL Injection in PHP?
Using prepared statements or mysqli_real_escape_string().
6. How do you connect PHP to a MySQL database?
$conn = mysqli_connect("localhost", "root", "", "dbname");
7. What does mysqli_query() do?
Executes a SQL query against the database.
8. What is CRUD?
Stands for Create, Read, Update, and Delete — basic operations in a database.
Miscellaneous Web Programming Questions
1. What is client-side scripting?
Code executed on the user’s browser (e.g., JavaScript).
2. What is server-side scripting?
Code executed on the web server before the page is sent to the browser (e.g., PHP).
3. What is AJAX?
Asynchronous JavaScript and XML — allows data exchange without reloading the page.
4. What is JSON?
JavaScript Object Notation — a lightweight data-interchange format, easier to parse than XML.
5. What is the purpose of the header() function in PHP?
Used to send HTTP headers, such as redirects or content type.
6. What is error handling in PHP?
Managing errors using try, catch, and custom error handlers.
7. What is XSS (Cross-Site Scripting)?
A security issue where malicious scripts are injected into web pages viewed by others.
Localhost and Web Server Basics
1. What is “localhost”?
“Localhost” refers to your own computer acting as a server.
IP Address of localhost = 127.0.0.1
2. What is a Web Server?
A web server is software that delivers web pages to clients via HTTP/HTTPS.
Examples: Apache, Nginx, IIS.
3. What is the default port number for localhost?
HTTP → 80
HTTPS → 443
MySQL → 3306
4. What is XAMPP/WAMP/MAMP?
Local development stacks including Apache, MySQL/MariaDB, and PHP.
5. What is the function of Apache in XAMPP?
Processes HTTP requests and serves HTML/PHP pages to the browser.
6. What is MySQL in XAMPP?
A database management system used to store, manage, and retrieve data.
7. What is phpMyAdmin?
A web-based tool for managing MySQL databases.
8. What is the default username and password for MySQL in XAMPP/WAMP?
Username: root
Password: (blank)
9. How can you access phpMyAdmin?
http://localhost/phpmyadmin
MySQL User and Authentication
1. What is the MySQL root user?
The superuser account with full privileges.
2. What is the difference between MySQL root and OS root?
MySQL root → database superuser.
OS root → system administrator.
3. How can you change the MySQL root password?
Via phpMyAdmin → User accounts → Edit privileges → Change password
Using SQL:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
FLUSH PRIVILEGES;
4. Where are MySQL user details stored?
In mysql.user table inside the MySQL system database.
5. What is the purpose of localhost in MySQL users table?
Restricts the user to connect only from the local computer.
6. How can you connect to MySQL from the command line?
mysql -u root -p
7. What do -u and -p mean in MySQL command?
-u → username
-p → prompt for password
8. What is the default system database in MySQL?
mysql
9. What should you do if phpMyAdmin shows “Access denied for user root@localhost”?
Check if MySQL service is running.
Verify username/password in config.inc.php.
Reset MySQL root password if needed.
10. What file stores phpMyAdmin configuration?
config.inc.php
11. Difference between localhost and 127.0.0.1?
Both refer to the local machine; localhost resolves via DNS, 127.0.0.1 directly uses the IP.
12. How to verify if MySQL service is running?
XAMPP Control Panel → Check if MySQL is running.
Command prompt: netstat -an | find "3306"
PHP & Database Connection
1. How do you connect PHP to MySQL?
$conn = mysqli_connect("localhost", "root", "", "mydatabase");
2. What happens if the password is wrong?
Connection fails: Access denied for user 'root'@'localhost'.
3. What is a connection string?
Contains host, username, password, and database name to connect to MySQL.
4. Function to close a MySQL connection?
mysqli_close($conn);
5. How to check if MySQL connection is successful?
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
} else { echo "Connected successfully";}