webd assignment-1
webd assignment-1
AND
DEVELOPMENT
Assigment-2
Ans <?php
function sumOfEvenDigits($num) {
$sum = 0;
if ($digit % 2 == 0) {
$sum += $digit;
return $sum;
// Example usage:
$number = 123456;
$evenSum = sumOfEvenDigits($number);
Output :
Ques 2. Write a script in PHP to display a Multiplication Table.
Ans. <?php
?>
Output:
Ques 3. Design a Student Registration form, using appropriate input fields consisting of following:
a. Roll Number
b. First Name
c. Last Name
d. Gender
e. Department
f. DOB
Submit and retrieve the form data using the $_POST variable and display it.
<html>
<head>
</head>
<body>
<label for="gender">Gender:</label>
<label for="male">Male</label>
<label for="female">Female</label>
<label for="other">Other</label><br><br>
<label for="department">Department:</label>
</select><br><br>
</form>
</body>
</html>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$roll_number = $_POST["roll_number"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$gender = $_POST["gender"];
$department = $_POST["department"];
$dob = $_POST["dob"];
?>
Input:
Output (Html ):
Ques 4. Write PHP Code to create a database, connect to it, create tables, insert and access their
contents.
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "myDB";
// Create connection
if ($conn->connect_error) {
?>
2. Creating a Database:
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
// Create connection
// Check connection
if ($conn->connect_error) {
// Create database
} else {
$conn->close();
?>
3. Creating a Table:
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "myDB";
// Create connection
// Check connection
if ($conn->connect_error) {
// Create table
email VARCHAR(50),
)";
} else {
$conn->close();
?>
4. Inserting Data:
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "myDB";
// Create connection
// Check connection
if ($conn->connect_error) {
} else {
$conn->close();
?>
5. Retrieving Data:
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "myDB";
// Create connection
// Check connection
if ($conn->connect_error) {
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
} else {
$conn->close();
?>