Iwt PT 04 Ans
Iwt PT 04 Ans
CSE
19CS63C – INTERNET AND WEB TECHNOLOGIES
QUESTIONS- PREPARATORY TEST 04
Exam Date : 20/03/2025
1. How arrays are declared in PHP? Write a PHP script to demonstrate the usage of associative
array in PHP.
In PHP, arrays can be declared using the array() function or square brackets []. PHP supports three types of
arrays:
// Accessing elements
echo "Student Name: " . $student["name"] . "<br>";
echo "Age: " . $student["age"] . "<br>";
echo "Email: " . $student["email"] . "<br>";
echo "Course: " . $student["course"] . "<br>";
?>
Explanation:
• The keys (name, age, email, course) are strings, making it an associative array.
• We use $array_name["key"] to access values.
2. Implement and login form validation with username, password and email fields usingPHP
regular expression.
$username_pattern = "/^[a-zA-Z0-9_]{5,15}$/";
$password_pattern = "/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/";
$email_pattern = "/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/";
if (!preg_match($username_pattern, $username)) {
echo "Invalid Username!<br>";
}
if (!preg_match($password_pattern, $password)) {
echo "Invalid Password!<br>";
}
if (!preg_match($email_pattern, $email)) {
echo "Invalid Email!<br>";
} else {
echo "Login Successful!";
}
}
?>
<form method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
Email: <input type="text" name="email"><br>
<input type="submit" value="Login">
</form>
3. Create an E-mail registration form using PHP. The form should contain username, password,
Email id, gender, city using various input controls such as textboxes, radio button, combo boxes,
and submit button. When you click the submit button, the form data will be submitted into the
database.
<?php
$conn = new mysqli("localhost", "root", "", "user_db");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = password_hash($_POST["password"], PASSWORD_BCRYPT);
$email = $_POST["email"];
$gender = $_POST["gender"];
$city = $_POST["city"];
$query = "INSERT INTO users (username, password, email, gender, city) VALUES ('$username',
'$password', '$email', '$gender', '$city')";
<?php
if (isset($_POST['set_cookie'])) {
setcookie("user", "John", time() + 3600, "/");
echo "Cookie 'user' is set!";
} elseif (isset($_POST['get_cookie'])) {
if (isset($_COOKIE["user"])) {
echo "Welcome, " . $_COOKIE["user"];
} else {
echo "Cookie is not set!";
}
} elseif (isset($_POST['delete_cookie'])) {
setcookie("user", "", time() - 3600, "/");
echo "Cookie 'user' is deleted!";
}
?>
<form method="post">
<button type="submit" name="set_cookie">Set Cookie</button>
<button type="submit" name="get_cookie">Get Cookie</button>
<button type="submit" name="delete_cookie">Delete Cookie</button>
</form>
5. Explain Document Type definition with its syntax. Validate the correctness of the below
XMLdocument using XML DTD with PCDATA and CDATA
<Item>
<StudentID> 010533 </StudentID>
<Name> Ramkumar </Name>
<Nationality> 01 </Nationality>
<Gender> L </Gender>
<State> 14 </State>
<Result> 2.60 </Result>
</Item>
DTD (Document Type Definition) defines the structure, elements, and attributes of an XML document. It
ensures that XML data follows a specific format, making it valid and consistent.
1. Syntax of DTD
6. Explain XML Scheme Definition with its syntax. Validate the correctness of the below XML
document using XSD (XML Scheme Definition).
XML Schema Definition (XSD) Explanation
XML Schema Definition (XSD) is used to define the structure and rules for an XML document. It ensures that
the XML document follows a predefined format by specifying:
7. Implement the XML document for student object and represent the student data as tableview using
XSL.
XML Document (student.xml)
xml
CopyEdit
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="student.xsl"?>
<Students>
<Student>
<ID>010533</ID>
<Name>Ramkumar</Name>
<Nationality>India</Nationality>
<Gender>Male</Gender>
<State>Tamil Nadu</State>
<Result>2.60</Result>
</Student>
<Student>
<ID>010534</ID>
<Name>Anjali</Name>
<Nationality>India</Nationality>
<Gender>Female</Gender>
<State>Karnataka</State>
<Result>3.50</Result>
</Student>
</Students>