Practical - 9 IWD

 

Aim: Information passing using Hidden variables (POST method)

Page–1: Send data using hidden variable

File Name: page1.php

<!DOCTYPE html> <html> <head> <title>Page 1</title> </head> <body> <h2>Enter Employee Name</h2> <form method="post" action="page2.php"> Employee Name: <input type="text" name="empname"><br><br> <input type="hidden" name="company" value="ABC Technologies"> <input type="submit" value="Send"> </form> </body> </html>

Page–2: Receive hidden variable data

File Name: page2.php

<!DOCTYPE html> <html> <head> <title>Page 2</title> </head> <body> <h2>Received Information</h2> <?php echo "Employee Name: " . $_POST['empname'] . "<br>"; echo "Company Name: " . $_POST['company']; ?> </body> </html>

Explanation (for exam):

  • Hidden variable stores data invisibly

  • Data is passed using POST method

  • Accessed using $_POST[] array


Key Viva Questions

  1. What is a hidden variable?
    → A hidden variable stores data in a form but is not visible to the user.

  2. Which method is used here?
    → POST method

  3. How do you access form data in PHP?
    → Using $_POST array

Comments

Popular posts from this blog

Unit I - Introduction to PHP

Practical - 1 IWD

Practical - 10 IWD