DWPD - Viva questions & short answers

 

Viva questions & short answers — based on your practical aims

Below are concise, exam-ready viva questions and answers for each practical aim you listed. Use them to practise — each answer is short, direct and includes key code snippets or commands you can state during a viva.


  1. Q: How do you display an image in HTML?
    A: Use the <img> tag with src and alt. Example: <img src="images/photo.jpg" alt="My Photo" width="300">.

  2. Q: How do you create a hyperlink in HTML?
    A: Use the <a> tag with href. Example: <a href="https://example.com">Visit</a>. For internal links use href="page.html" or href="#section".

  3. Q: How do you embed a video in a webpage using the embed tag?
    A: Use <embed> or preferably <video>/<iframe>. Example (embed): <embed src="videos/sample.mp4" width="640" height="360">. Better: <video controls src="videos/sample.mp4" width="640"></video>.

  4. Q: How do you create a feedback form (HTML form handling)?
    A: Use <form> with input controls and action to server script. Example:

    <form action="submit_feedback.php" method="post"> <input name="name"> <textarea name="feedback"></textarea> <button type="submit">Send</button> </form>
  5. Q: How to create a contact form?
    A: Similar to feedback form; include name, email, subject, message. Use type="email" for email validation and method="post". Example fields: <input name="email" type="email">.

  6. Q: How do you create a static page layout using <div> tags?
    A: Use semantic layout with <div id="header">, <div id="nav">, <div id="content">, <div id="footer"> and apply CSS for widths/float or flexbox. Example:

    <div id="container"> <div id="header">Header</div> <div id="nav">Menu</div> <div id="main">Main</div> <div id="footer">Footer</div> </div>
  7. Q: How do you design a menu system using list tags?
    A: Use <ul>/<li> and style with CSS. Example:

    <ul class="menu"> <li><a href="home.html">Home</a></li> <li><a href="about.html">About</a></li> </ul>
  8. Q: How would you replicate or design a Google-like page using HTML5?
    A: Minimal layout: an input box centered, two buttons, clean header/footer. Use <header>, <main>, <footer>, placeholder text. Example: <input type="text" placeholder="Search Google">.

  9. Q: How do you apply CSS formatting to pages and use ready-made templates?
    A: Link CSS via <link rel="stylesheet" href="style.css"> or use inline <style>. For templates, download CSS library or template and integrate HTML classes. Explain properties (margin, padding, display, flex/grid).

  10. Q: How to print a welcome message in PHP?
    A: Use echo or print. Example: <?php echo "Welcome to PHP!"; ?>.

  11. Q: How do you demonstrate arithmetic, comparison and logical operators in PHP?
    A: Show examples:

    $a=5; $b=2; $sum = $a + $b; // arithmetic $isEqual = ($a == $b); // comparison $res = ($a > 0) && ($b > 0); // logical
  12. Q: How to get the type of a variable in PHP?
    A: Use gettype($var). Example: echo gettype(3.14); // "double".

  13. Q: How to set type of a variable using settype() in PHP?
    A: settype($var, "integer"); This converts $var to integer and returns true on success.

  14. Q: How to change type using type casting in PHP?
    A: Use casting like (int)$var, (string)$var. Example: $i = (int)$str;.

  15. Q: How to print Fibonacci series in PHP?
    A: Simple loop example:

    $n=10; $a=0; $b=1; for($i=0;$i<$n;$i++){ echo $a." "; $t = $a + $b; $a = $b; $b = $t; }
  16. Q: How to calculate total marks and display grade in PHP?
    A: Sum marks, compute percentage, use if for grade. Example:

    $total = $m1+$m2+$m3; $percent = $total/3; if($percent>=75) $grade='A'; elseif($percent>=60) $grade='B'; else $grade='C';
  17. Q: How to find the maximum of three numbers in PHP?
    A: Use max($a,$b,$c) or nested if. Example: $max = max($x,$y,$z);.

  18. Q: How to add two 2x2 matrices in PHP (2D arrays)?
    A: Example:

    $A=[[1,2],[3,4]]; $B=[[5,6],[7,8]]; $C=[]; for($i=0;$i<2;$i++){ for($j=0;$j<2;$j++){ $C[$i][$j] = $A[$i][$j] + $B[$i][$j]; } }
  19. Q: How to use associative arrays and foreach loop in PHP?
    A: Example:

    $arr = ["name"=>"Jay","age"=>22]; foreach($arr as $key=>$val){ echo "$key => $val"; }
  20. Q: How to write and call a user-defined function in PHP?
    A: Example:

    function add($x,$y){ return $x+$y; } echo add(3,4);
  21. Q: How to demonstrate string functions in PHP?
    A: Use strlen(), str_replace(), strpos(), substr() etc. Example: echo strtoupper("hello"); // HELLO.

  22. Q: How to demonstrate date/time and math functions in PHP?
    A: Date/time: date("Y-m-d H:i:s"), time(). Math: abs(), round(), pow(), rand(). Example: echo date("d-m-Y");.

  23. Q: How to create a form with textbox, checkbox, radio, select and display values on new PHP page?
    A: HTML form:

    <form action="process.php" method="post"> <input name="name" type="text"> <input type="checkbox" name="hobby[]" value="music"> <input type="radio" name="gender" value="M"> <select name="course"><option>IT</option></select> <input type="submit"> </form>

    In process.php use $_POST['name'], $_POST['hobby'](array), $_POST['gender'].

  24. Q: How to pass variables through a URL in PHP?
    A: Append query string: page.php?name=Jay&age=22. Retrieve with $_GET['name'].

  25. Q: Give two different methods to pass variables through a URL.
    A: 1) Anchor link: <a href="page.php?x=1">Link</a>. 2) Form with method="get": <form method="get">.

  26. Q: How to pass variables using hidden inputs?
    A: Use <input type="hidden" name="id" value="123"> and read via $_POST['id'] (or $_GET if method get).

  27. Q: How to pass variables with sessions in PHP?
    A: Start session session_start(); $_SESSION['user']="Jay"; Then on other page session_start(); echo $_SESSION['user'];.

  28. Q: How to pass variables with cookies in PHP?
    A: Use setcookie("user","Jay", time()+3600); then retrieve $_COOKIE['user'].

  29. Q: How to keep track of how many times a visitor has loaded the page?
    A: Use cookie or session counter. Example with cookie:

    $count = isset($_COOKIE['visit']) ? $_COOKIE['visit']+1 : 1; setcookie('visit',$count,time()+3600*24*30); echo "Visit: $count";
  30. Q: How to upload an image with extension gif or jpeg in PHP?
    A: Use <form enctype="multipart/form-data"> and in PHP check $_FILES['file']['type'] or pathinfo() extension, move with move_uploaded_file(). Validate MIME and extension.

  31. Q: How to create watermarks using imagecopymerge() in PHP?
    A: Use GD library: load base image and watermark, then imagecopymerge($base, $watermark, x, y, 0,0, $w, $h, $pct); and output with imagejpeg().

  32. Q: How to convert an image to grayscale in PHP?
    A: Use GD: load image, call imagefilter($img, IMG_FILTER_GRAYSCALE); then save with imagejpeg().

  33. Q: How to connect to MySQL from PHP?
    A: Use mysqli or PDO. Example mysqli:

    $conn = new mysqli("localhost","user","pass","db"); if($conn->connect_error) die("Connection failed");
  34. Q: How to create and drop a database with PHP?
    A: Use SQL queries via PHP:

    $conn->query("CREATE DATABASE mydb"); $conn->query("DROP DATABASE mydb");
  35. Q: How to create a database using phpMyAdmin?
    A: Log in to phpMyAdmin → click "Databases" → enter name → click "Create". (Describe UI steps.)

  36. Q: How to read data from a table and display it in tabular form?
    A: Run SELECT query, loop results and generate an HTML <table>. Example:

    $res = $conn->query("SELECT * FROM students"); echo "<table>"; while($row = $res->fetch_assoc()){ echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td></tr>"; } echo "</table>";
  37. Q: How to manipulate data (insert/update/delete) from table and display it?
    A: Use INSERT, UPDATE, DELETE queries via $conn->query() and show success/failure messages. After change, re-run SELECT to display.

  38. Q: How to develop a small PHP application using forms and database?
    A: Example steps: design DB schema, create HTML form, handle input in PHP ($_POST), validate, connect to DB, execute insert/update, show confirmation and list records. Mention security: input validation and prepared statements.

  39. Q: What security practices should you follow when handling forms and DB?
    A: Use prepared statements to prevent SQL injection, validate/sanitize inputs, use CSRF tokens for forms, limit file upload types/sizes, escape output with htmlspecialchars().

  40. Q: How to validate form input on client and server side?
    A: Client-side: use HTML attributes (required, type="email") and JavaScript. Server-side: validate using PHP functions and regex; never trust client-side only.

  41. Q: How do you handle file permissions for uploads?
    A: Ensure upload folder has write permission for web server but no execute permissions. Store outside web root if possible or restrict access via .htaccess.

  42. Q: Explain the difference between GET and POST.
    A: GET appends data to URL (visible, length-limited) and is idempotent. POST sends data in request body (not in URL), used for forms that change server state or send large/secure data.

  43. Q: Why use prepared statements?
    A: To prevent SQL injection and separate query structure from data. Example PDO: $stmt = $pdo->prepare("INSERT INTO table (a) VALUES (?)"); $stmt->execute([$val]);.

  44. Q: How to debug PHP code?
    A: Use error_reporting(E_ALL); ini_set('display_errors',1);, inspect logs, use var_dump()/print_r(), use Xdebug for step debugging.

  45. Q: How to set up a local PHP+MySQL development environment?
    A: Install XAMPP/WAMP/LAMP, place files in htdocs or www, start Apache and MySQL, open http://localhost/.

  46. Q: How to use sessions securely?
    A: Use session_start(); set session.cookie_httponly = true, use HTTPS, regenerate session id after login (session_regenerate_id(true)), and store minimal info.

  47. Q: How to store images in DB vs file system — pros and cons?
    A: DB (BLOB): easier backup/ACID but larger DB size and slower. File system: faster for serving files and simpler, but need to manage file paths and backups.

  48. Q: How to perform CRUD operations in PHP?
    A: Use SQL inside PHP: Create (INSERT), Read (SELECT), Update (UPDATE), Delete (DELETE), typically via prepared statements and then display result.

  49. Q: What are some common PHP image functions for manipulation?
    A: imagecreatefromjpeg(), imagecopymerge(), imagefilter(), imagejpeg(), imagesx(), imagesy().

  50. Q: How do you secure file uploads (image upload example)?
    A: Check MIME and extension, limit file size, rename uploaded files, store outside web root, set strict permissions, and scan for malicious content.


A. DEFINITIONS & CONCEPTUAL QUESTIONS WITH ANSWERS

1. What is HTML?

Answer:
HTML (HyperText Markup Language) is the standard language used to create the structure of webpages using tags like <p>, <div>, <img>, etc.


2. What is a Tag and an Attribute in HTML?

Answer:

  • Tag: An instruction enclosed in < > used to tell the browser how to display content. Example: <h1>.

  • Attribute: Additional information within a tag. Example: <img src="photo.jpg" alt="img">.


3. What is Hyperlinking?

Answer:
Hyperlinking connects one document/webpage to another using the <a> tag with href.


4. What is the purpose of the <form> tag?

Answer:
The <form> tag collects user input and sends it to a server using GET or POST.


5. Difference between GET and POST methods.

Answer:

GETPOST
Sends data in URLSends data in body
Less secureMore secure
Limited dataLarge data allowed
Use for view/searchUse for insert/update

6. What is CSS?

Answer:
CSS (Cascading Style Sheets) is used to style HTML pages—colors, layout, fonts, spacing, etc.


7. What is the difference between Inline, Internal, and External CSS?

Answer:

  • Inline: Inside tag → <p style="color:red">.

  • Internal: In <style> inside <head>.

  • External: In .css file using <link> tag.


8. What is PHP?

Answer:
PHP (Hypertext Preprocessor) is a server-side scripting language used to generate dynamic pages and connect with databases.


9. What are Variables in PHP?

Answer:
Variables are containers for storing data; they start with $ like $name = "Jay";.


10. What is an Array?

Answer:
An array is a collection of values stored under one variable name.


11. Types of Arrays in PHP?

Answer:

  1. Indexed Array

  2. Associative Array

  3. Multidimensional Array


12. What is a Function?

Answer:
A function is reusable code that performs a task. Example:
function sum($a,$b){ return $a+$b; }


13. What is a String Function?

Answer:
Functions used to manipulate strings, e.g., strlen(), strtoupper(), substr(), etc.


14. What is Session in PHP?

Answer:
A session stores user information on the server across multiple pages using $_SESSION.


15. What is a Cookie?

Answer:
A cookie stores small data in the user’s browser using setcookie().


16. Difference Between Session and Cookie.

SessionCookie
Stores on serverStores in browser
More secureLess secure
Auto-destroy on closePersistent

17. What is MySQL?

Answer:
MySQL is an open-source relational database used to store and manage data in tables.


18. What is Primary Key?

Answer:
A field that uniquely identifies a record and cannot be duplicate or NULL.


19. What is Foreign Key?

Answer:
A field in one table which refers to primary key of another table → used to create relationships.


20. What is SQL?

Answer:
SQL (Structured Query Language) is used to insert, delete, update, and retrieve data from databases.


21. What is XAMPP/WAMP?

Answer:
Local server software that provides Apache, PHP, and MySQL for development.


22. What is Form Validation?

Answer:
Checking if entered data is correct before submitting form (e.g., email format, required fields).


23. What is Database Connectivity in PHP?

Answer:
Connecting PHP with MySQL using mysqli or PDO to run queries.


24. What is File Uploading in PHP?

Answer:
Uploading files (images, documents) using <form enctype="multipart/form-data"> and processing via $_FILES.


25. What is GD Library in PHP?

Answer:
A library used for image processing: watermarking, resizing, grayscale, merging.


26. What is Image Watermarking?

Answer:
Adding a transparent logo/text on an image using imagecopymerge().


27. What is Type Casting?

Answer:
Forcing a variable to change type: (int)$var, (string)$var.


28. What is settype()?

Answer:
A PHP function that changes the type of a variable in-place.


29. What is Form Handling in PHP?

Answer:
Data submitted by user is captured using $_POST or $_GET, processed, and stored/displayed.


30. What are Date and Time functions?

Answer:
Functions like date(), time(), strtotime() used to work with date/time.


31. What are Arithmetic Operators?

Answer:
+, -, *, /, %, **


32. What are Logical Operators?

Answer:
&&, ||, !


33. What is URL Passing?

Answer:
Sending data through URL query string using $_GET.


34. What is Hidden Field?

Answer:
A form input not visible to user: <input type="hidden">.


35. What is PHP Output Function?

Answer:
echo and print are used to display output on browser.


B. EXTRA VIVA QUESTIONS 

(CONCEPTUAL)

Here are extra mixed viva questions for stronger preparation:

36. What is Doctype? Why is it used?

It tells browser which HTML version the file uses. Example: <!DOCTYPE html> for HTML5.

37. What is Responsive Web Design?

A design technique that adjusts layout for mobile/tablet/desktop using CSS media queries.

38. What is Semantic HTML?

HTML5 tags with meaning like <header>, <footer>, <nav>, <article>.

39. What is the use of <div> and <span>?

  • <div> is block-level container.

  • <span> is inline container.

40. What is the box model in CSS?

Every element has margin → border → padding → content.

41. What is an Echo Statement in PHP?

Echo prints output on screen: echo "Hello";

42. What is include and require in PHP?

Used to insert one PHP file into another.

  • include shows warning;

  • require shows fatal error.

43. What is the difference between MySQL and SQL?

MySQL = database software.
SQL = language used to communicate with database.

44. What is CRUD?

Create, Read, Update, Delete — main DB operations.

45. What is an ID and Class in CSS?

  • ID (#id) is unique.

  • Class (.class) can repeat.



PURE CONCEPTS OF HTML

1. What is HTML?

HTML (HyperText Markup Language) is the standard language used to create the structure of webpages. It uses tags to define elements.


2. What is an HTML Document Structure?

Basic structure includes:

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> Content goes here… </body> </html>

3. What are HTML Tags?

Tags are predefined keywords enclosed in < >.
Example: <p>, <a>, <div>, <img>.


4. What are HTML Elements?

An element = start tag + content + end tag
Example: <p>This is a paragraph.</p>


5. What are Attributes?

Additional information added inside tags.
Example: <img src="pic.jpg" alt="photo">


6. What are Block-level & Inline Elements?

  • Block-level: Start on a new line (<div>, <h1>, <p>, <ul>).

  • Inline: Do not start a new line (<span>, <a>, <img>).


7. What is Semantic HTML?

Tags that describe meaning:
<header>, <footer>, <section>, <nav>, <article>.


8. What is Hyperlink?

Used to navigate to another page:
<a href="page.html">Click</a>


9. What is the <form> tag?

Used to collect user input. Contains:

  • <input>

  • <textarea>

  • <select>

  • <button>


10. What is HTML5?

Latest version that supports:
✔ Semantic tags
✔ Audio & video
✔ Canvas
✔ Local storage
✔ Form validation


11. What is an iframe?

Used to embed another webpage inside a page:
<iframe src="page.html"></iframe>


12. What is DOCTYPE?

Declaration that tells the browser which HTML version is used:
<!DOCTYPE html>


PURE CONCEPTS OF CSS

1. What is CSS?

CSS (Cascading Style Sheets) is used to style HTML pages (colors, fonts, layout).


2. Types of CSS?

  1. Inline CSS – inside tag

  2. Internal CSS – inside <style>

  3. External CSS – linked .css file


3. What is the CSS Box Model?

Every HTML element behaves like a box with:
Content → Padding → Border → Margin


4. What are Selectors in CSS?

Used to target HTML elements.

  • Element selector: p {}

  • Class selector: .title {}

  • ID selector: #header {}

  • Group selector: h1, p {}

  • Universal selector: * {}


5. What is Specificity?

Rules to decide which CSS style is applied when multiple rules conflict.

Hierarchy:

  1. Inline

  2. ID

  3. Class

  4. Tag

  5. Universal


6. What is Flexbox?

A layout model for designing flexible, responsive layouts using:
display: flex;
Used for alignment, spacing, centering, and arranging elements.


7. What is CSS Grid?

Two-dimensional layout system used to create rows and columns easily.


8. What is Responsive Design?

Design that adapts to screen sizes using media queries:

@media (max-width:600px){ body { background: lightblue; } }

9. What is External CSS and why use it?

Styles in a separate .css file, linked using:

<link rel="stylesheet" href="style.css">

Used for better organization and reusability.


10. What are Pseudo-classes and Pseudo-elements?

  • Pseudo-class: Applies styling to specific states
    Example: a:hover

  • Pseudo-element: Styles part of an element
    Example: p::first-letter


11. What is the difference between display: block, inline, inline-block?

  • block: full width

  • inline: no width/height control

  • inline-block: inline behavior but allows width/height


12. What is Z-index?

Controls overlapping of elements (stack order).




PURE CONCEPTS OF PHP

1. What is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language used to create dynamic web applications.


2. How PHP works?

  1. Browser sends request

  2. Server executes PHP file

  3. PHP processes logic

  4. Output (HTML) sent back to browser


3. What is a Variable in PHP?

A variable stores data and starts with $.
Example: $name = "Jay";


4. Data Types in PHP

  • String

  • Integer

  • Float

  • Boolean

  • Array

  • Object

  • NULL


5. What are Operators?

Used to perform operations:

  • Arithmetic (+ - * /)

  • Comparison (== != > <)

  • Logical (&& || !)

  • Assignment (= +=)


6. What are Arrays?

Collection of values:

  • Indexed array

  • Associative array

  • Multidimensional array


7. What is a Function?

A reusable block of code:

function sum($a,$b){ return $a+$b; }

8. What is Form Handling?

Retrieving data using:

  • $_GET

  • $_POST


9. What are Sessions?

Server-side storage for maintaining user data across pages:

session_start(); $_SESSION['user']="Jay";

10. What are Cookies?

Client-side storage saved in browser:

setcookie("user","Jay", time()+3600);

11. What is File Upload in PHP?

Using:

  • $_FILES

  • move_uploaded_file()
    Requires enctype="multipart/form-data".


12. What is MySQL in PHP?

A database used for storing and managing data, accessed using:

  • mysqli

  • PDO


13. What is CRUD?

Basic operations:

  • Create

  • Read

  • Update

  • Delete


14. What is Prepared Statement?

A secure SQL statement used to prevent SQL injection.


15. What is GD Library?

Used for image processing:

  • Resize

  • Watermark

  • Grayscale

  • Create images


16. What is Echo and Print?

Functions used to output data:

  • echo "Hello";

  • print "Hello";


17. What is Include and Require?

Used to include external PHP files:

  • include: warning

  • require: fatal error


18. What is Type Casting in PHP?

Converting variable types manually:
$num = (int)$string;


19. What is settype()?

Changing type of variable programmatically:
settype($var,"integer");


20. What is Server-Side vs Client-Side?

  • PHP = Server-side

  • HTML/CSS/JS = Client-side

Comments

Popular posts from this blog

Short overview on Unit-II

Short Overview on Unit - I

Unit - 1 Question and Answer