WebTech Assignment 2
WebTech Assignment 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Detection</title>
</head>
<body>
<h1 id="browser"></h1>
<script>
// Function to detect the browser name
function detectBrowser() {
var browserInfo = navigator.userAgent;
var browserName;
if (browserInfo.includes('Opera') || browserInfo.includes('Opr')) {
browserName = 'Opera';
} else if (browserInfo.includes('Edg')) {
browserName = 'Edge';
} else if (browserInfo.includes('Chrome')) {
browserName = 'Chrome';
} else if (browserInfo.includes('Safari')) {
browserName = 'Safari';
} else if (browserInfo.includes('Firefox')) {
browserName = 'Firefox'
} else {
browserName = 'unknown browser'
}
</body>
</html>
Q2)
<script>
const form = document.getElementById('registrationForm');
form.addEventListener('submit', function(event) {
event.preventDefault();
if (!emailRegex.test(email)) {
alert("Invalid email address!");
return;
}
if (!passwordRegex.test(password)) {
alert("Invalid password! It should be at least 8 characters long and contain at least one uppercase
letter, one digit, and one special character.");
return;
}
if (!mobileRegex.test(mobileNumber)) {
alert("Invalid mobile number! It should contain 10 digits only.");
return;
}
Q3) (a)
<?php
$a = 20;
$b = 42;
$additionResult = $a + $b;
$subtractionResult = $b - $a;
$multiplicationResult = $a * $b;
$divisionResult = $b / $a;
$modulusResult = $b % $a;
$incrementResult = ++$b;
$decrementResult = --$b;
Q3) (b)
<?php
function isPalindrome($str) {
$cleanedStr = strtolower(str_replace(' ', '', $str));
return $cleanedStr === strrev($cleanedStr);
}
$inputString = "Naman";
if (isPalindrome($inputString)) {
echo "The string '$inputString' is a palindrome.";
} else {
echo "The string '$inputString' is not a palindrome.";
}
?>
Q3) (c)(i)
<?php
// MySQL database created with a table named 'users'
// containing columns 'id', 'name', 'email', and 'phone'
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$servername = "localhost:3307"; // Change to your database server name
$username = "root"; // Change to your database username
$password = ""; // Change to your database password
$dbname = "practice"; // Change to your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->close();
}
?>
Q3) (c)(ii)
<?php
$servername = "localhost:3307";
$username = "root";
$password = "";
$dbname = "practice";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["id"] . "</td>
<td>" . $row["name"] . "</td>
<td>" . $row["email"] . "</td>
<td>" . $row["phone"] . "</td>
</tr>";
}
echo "</table>";
} else {
echo "No data found.";
}
$conn->close();
?>