practical - Week 2

2023-08-23

Practical 1: Create a simple HTML form and accept the user name and on submitting the form greets the user with welcome message through PHP echo statement.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<center>
<h1>Enter your name here </h1>    
    <form name="greeting" method="get">
        <input  type = "text" 
                name = "name" 
                value= "<?php echo $_GET['name']?>" />
        <input type="submit">
    </form>
<?php
$name = $_GET['name'];
if(isset($name))
    print("<h3> Hello $name </h3>");
?>
</center>
</body> 
</html>

Practical 2: Create a html form that takes integer (1 to 10 only) and displays that number is even or odd

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<center>
<h1>Enter your number here </h1>    
    <form name="greeting" method="get">
        <input  type="number" 
                name="num" 
                min = "1"
                max = "10"
                value= "<?php echo $_GET['num']?>" />
        <input type="submit">
    </form>
<?php
$num  = $_GET['num'];
$fact = 1;
if(isset($num))  {
    if($num % 2 == 0) {
        print("<h3> Number is even </h3>");
    } else {
        print("<h3> Number is odd </h3>");
    }
}

Practical 3: Create a html form that takes integer (1 to 10 only) and displays the table of that number

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<center>
<h1>Enter your number here </h1>    
    <form name="num" method="get">
        <input  type="number" 
                name="num" 
                min = "1"
                max = "10"
                value= "<?php echo $_GET['num']?>" />
        <input type="submit">
    </form>
<?php    
$num  = $_GET['num'];
for($i=1; $i<=10; $i++)   
{
$product = $i*$num;
echo "$num * $i = $product" ;   
echo '<br>';     
}  
?>