0% found this document useful (0 votes)
19 views

Example of different PHP programs

Uploaded by

jonatha98637726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Example of different PHP programs

Uploaded by

jonatha98637726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

PHP PROGRAMS.

Displaying Names into Twenty Times:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>My_Name in 20 Times</title>
</head>
<body bgcolor="gold">
<center>
<strong>
<?php
for ($i=1; $i <=20 ; $i++) {
echo "Jonathan <br>";
}

?>
</strong>
</center>
</body>
</html>

Displaying A in Triangle format:


RAMECK TUYISENGEIJONATHAN_AS 1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>Loop for AAAA more</title>
</head>
<body bgcolor="silver">
<?php
$rows=12;
for ($i=1; $i <=$rows; $i++) {
for ($j=1; $j <=$rows-$i; $j++) {
echo "";
}
for ($k=1; $k <=1*$i-1; $k++) {
echo "<b>Alice\n</b>";
}
echo "<br>";
}
?>
</body>
</html>

Displaying Hello from 1 to Hello 6:

RAMECK TUYISENGEIJONATHAN_AS 2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>Hello in 6-Phases</title>
</head>
<body bgcolor="cyan">
<center>
<?php
$i=1;
while ($i<=6) {
echo "<h3>Hello \n" .$i."</h3>";
$i++;
}

?>
</center>
</body>
</html>

Number Comparision:

<!DOCTYPE html>
<html lang="en">

RAMECK TUYISENGEIJONATHAN_AS 3
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>Comparison</title>
</head>
<body bgcolor="bisque"> <center>
<form action="" method="POST">
<div class="memo">
<h1 style="color: black; font-weight: bold; font-style: italic; font-
family: serif; font-size: 0.25in; text-shadow: 1px 1px blue;">
<marquee>
Comparison of numbers
</marquee></h1>
<label>Num1:</label>
<input type="text" name="Num1" value="" step="any"
pattern="[0-9]+" required/>
<br><br>
<label>Num2:</label>
<input type="text" name="Num2" value="" step="any"
pattern="[0-9]+" required/>
<br><br>
<label>Num3:</label>
<input type="text" name="Num3" value="" step="any"
pattern="[0-9]+" required/>
<br><br>
<button type="submit" name="compare">Compare</button>
<br><br>
RAMECK TUYISENGEIJONATHAN_AS 4
<style>
button {
color: whitesmoke;
background: black;
font-size: 0.19in;
font-weight: bold;
font-family: monospace;
border-radius: 5px;
}
</style>
</form>
<?php
if (isset($_POST['compare'])) {
$Num1 = $_POST['Num1'];
$Num2 = $_POST['Num2'];
$Num3 = $_POST['Num3'];
$Sum = $Num1+$Num2+$Num3;
if ($Num1>$Num2 && $Num1>$Num3) {
$conclusion = "$Num1 > $Num2 and $Num3";
}
if ($Num2>$Num1 && $Num2>$Num3) {
$conclusion = "$Num2 > $Num1 and $Num3";
}
if ($Num3>$Num2 && $Num3>$Num1) {
$conclusion = "$Num3 > $Num2 and $Num1";
}

RAMECK TUYISENGEIJONATHAN_AS 5
if ($Num1==$Num2 && $Num1>$Num3) {
$conclusion = "$Num1 \n = $Num2 but != $Num3";
}
if ($Num1==$Num3 && $Num1>$Num2) {
$conclusion = "$Num1 \n = $Num3 but != $Num2";
}

if ($Num2==$Num1 && $Num2>$Num3) {


$conclusion = "$Num2 \n = $Num1 but != $Num3";
}
if ($Num2==$Num3 && $Num2>$Num1) {
$conclusion = "$Num2 \n = $Num3 but != $Num1";
}

if ($Num3==$Num2 && $Num3>$Num1) {


$conclusion = "$Num3 \n = $Num2 but != $Num1";
}
if ($Num3==$Num1 && $Num3>$Num2) {
$conclusion = "$Num3 \n = $Num1 but != $Num2";
}

if ($Num1==$Num2&&$Num1==$Num3) {
$conclusion = "Both $Num1 \n $Num2 \n and $Num3 are
equal";
}

RAMECK TUYISENGEIJONATHAN_AS 6
echo "<h2 class='conclusion'>$conclusion <br> The Sum of
above Numbers is $Sum.</h2>";
}

?>
</div>
</center>
</body>
</html>
<style>
.memo {
background: beige;
border: 6px outset rosybrown;
border-radius: 0.3rem;
width: 55%;
margin: 45px 45px 60px 60px;
box-shadow: 2px 4px 4px 2px blue;
}
label{
color: black;
font-weight: bold;
font-size: 0.2in;
word-spacing: 12px;
letter-spacing: 2px;
font-family: Impact;
}

RAMECK TUYISENGEIJONATHAN_AS 7
input[type=text]{
color: black;
background: bisque;
font-weight: bold;
font-size: 0.2in;
word-spacing: 12px;
letter-spacing: 2px;
font-family: sans-serif;
border: 3px groove black;
border-radius: 6px;
}
</style>

Simple Calculator:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>Simple Calculator</title>
</head>
<body>
<center>

RAMECK TUYISENGEIJONATHAN_AS 8
<div class="myDiv">
<form method="POST" action="Calculator.php">
<h1 style="color: black; text-shadow: 2px 1px greenyellow;">
<marquee>
Simple Calculator
</marquee>
</h1>
<label for="N1">N1:</label><input type="number" name="N1"
step="any" required/><br><br>
<label for="N2">N2:</label><input type="number" name="N2"
step="any" required/><br><br>
<input type="radio" name="show" value="add" required
><label>Add</label>
<input type="radio" name="show" value="minus" required
><label>Minus</label>
<input type="radio" name="show" value="multiply" required
><label>Multiply</label>
<input type="radio" name="show" value="divide" required
><label>Divide</label>
<input type="radio" name="show" value="modulus" required
><label>Modulus</label>
<input type="radio" name="show" value="power" required
><label>Power</label><br><br>
<button type="submit" name="calculate" title="hold to get
answer">Calculate⇲</button>
<br><br>
</form>
<?php
if (isset($_POST['calculate'])) {
RAMECK TUYISENGEIJONATHAN_AS 9
$show = $_POST['show'];
$N1 = $_POST['N1'];
$N2 = $_POST['N2'];
switch ($show) {
case 'add':
$result = $N1+$N2;
break;
case 'minus':
$result = $N1-$N2;
break;
case 'multiply':
$result = $N1*$N2;
break;
case 'divide':
$result = $N1/$N2;
break;
case 'modulus':
$result = $N1%$N2;
break;
case 'power':
$result = $N1**$N2;
break;
}
echo "<h2 class='result'>Result ↣";
echo "$N1 $show $N2 ⇒ $result </h2>";
}

RAMECK TUYISENGEIJONATHAN_AS 10
?>
</div>
</center>
</body>
</html>
<style>
.myDiv {
background-image: linear-gradient(12deg,hotpink);
border: 3px ridge pink;
border-radius: 4px;
box-shadow: 2px 4px 2px 4px darkblue;
width: 65%;
margin-top: 1in;
}
label {
color: black;
font-weight: bold;
font-size: 0.25in;
font-style: italic;
font-family: serif;
text-shadow: 1px 1px red;
}
input[type=number] {
color: black;
background: bisque;
font-family: serif;

RAMECK TUYISENGEIJONATHAN_AS 11
font-weight: bold;
font-size: 0.25in;
border: 4px outset blue;
border-radius: 0.2rem;
}
button {color: black; background: beige; font-weight: bold; font-
family: serif; font-size: 0.25in; border-radius: 0.2rem}
input[type=radio] {
font-weight: bold;
font-size: larger;
}
</style>

If.. Statement:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>If..else Statement</title>
</head>
<body bgcolor="bisque">
<center>
<div class="myDiv">
<form action="Statement.php" method="POST">
RAMECK TUYISENGEIJONATHAN_AS 12
<h1 style="color: blue; text-shadow: 1px 1px magenta; font-
family: serif; font-weight: bold; font-size: 0.25in;">
Enter Marks⇩ To Get Result
</h1>
<label>M1:</label><input type="text" name="M1" step="any"
value="" required/> <br><br>
<label>M2:</label><input type="text" name="M2" step="any"
value="" required/> <br><br>
<label>M3:</label><input type="text" name="M3" step="any"
value="" required/> <br><br>
<button type="submit" name="check">Get_Result</button>
</form>
<?php
if (isset($_POST['check'])) {
$M1 = $_POST['M1'];
$M2 = $_POST['M2'];
$M3 = $_POST['M3'];
$sum = $M1+$M2+$M3;
$average = $sum/3; # $average=($M1+M2+M3)/3
echo "<h2>Sum Is $sum \n and Average Is $average <br> also
agregation is ↧ </h2>";
if ($average==100&&$average>=79) {
echo "<h2> Grade A </h2>";
}
if ($average<=78&&$average>=70) {
echo "<h2> Grade B </h2>";
}
if ($average<=69&&$average>=60) {
RAMECK TUYISENGEIJONATHAN_AS 13
echo "<h2> Grade C </h2>";
}
if ($average<=59&&$average>=50) {
echo "<h2> Grade D </h2>";
}
if ($average<=49&&$average>=30) {
echo "<h2> Grade E </h2>";
}
if ($average<=29&&$average>=0) {
echo "<h2> Grade F </h2>";
}
}
?>
</div>
</center>
</body>
</html>
<style>
.myDiv {
background-image: linear-
gradient(120deg,bisque,hotpink);
border: 3px ridge pink;
border-radius: 4px;
box-shadow: 2px 4px 2px 4px darkblue;
width: 65%;
margin-top: 1in;

RAMECK TUYISENGEIJONATHAN_AS 14
}
label {
color: black;
font-weight: bold;
font-size: 0.25in;
font-style: italic;
font-family: serif;
text-shadow: 1px 1px red;
}
button {color: black; background:gold; font-weight: bold; font-
family: monospace; font-size: 0.2in; border: 2px red dashed;
border-radius: 0.5rem;}
input[type=text] {
font-weight: bold;
font-size: larger;
}
</style>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>Trigonometric Option</title>
RAMECK TUYISENGEIJONATHAN_AS 15
</head>
<body>
<center>
<div class="myDiv">
<form action="" method="POST">
<h2 style="color: black; text-shadow: 2px 1px
greenyellow;">Trigonometric Options</h2>
TO:<input type="number" name="N3" title="Enter
Trigonometric Number" required><br><br>
<input type="radio" name="tri" value="cos"
required><label>Cosine</label>
<input type="radio" name="tri" value="sin"
required><label>Sine</label>
<input type="radio" name="tri" value="tan"
required><label>Tangent</label>
<input type="radio" name="tri" value="cotan"
required><label>Cotangent</label>
<input type="radio" name="tri" value="secant"
required><label>Secant</label>
<input type="radio" name="tri" value="cosecant"
required><label>Cosecant</label>
<br><br>
<button type="submit" name="trigonometric">Show
Answer</button>
</form>
<?php
if (isset($_POST['trigonometric'])) {
$N3 = $_POST['N3'];
$tri = $_POST['tri'];
RAMECK TUYISENGEIJONATHAN_AS 16
switch ($tri) {
case 'cos':
$Ans = cos($N3);
break;
case 'sin':
$Ans = sin($N3);
break;
case 'tan':
$Ans = tan($N3);
break;
case 'cotan':
$Ans = 1/tan($N3);
break;
case 'secant':
$Ans = 1/cos($N3);
break;
case 'cosecant':
$Ans = 1/sin($N3);
break;
}
echo "<h2 class='Ans'>Answer⇒";
echo "$N3 $tri ⇉ $Ans </h2>";
}
?>
</div><br>
</center>

RAMECK TUYISENGEIJONATHAN_AS 17
</body>
</html>
<style>
.myDiv {
background-image: linear-
gradient(12deg,orange,bisque,rebeccapurple);
border: 3px ridge pink;
border-radius: 4px;
box-shadow: 2px 4px 2px 4px darkblue;
width: 65%;
margin-top: 1in;
}
label {
color: black;
font-weight: bold;
font-size: 0.25in;
font-style: italic;
font-family: serif;
text-shadow: 1px 1px red;
}
input[type=number] {
color: magenta;
background: cyan;
font-family: sans-serif;
font-weight: bold;
font-size: 0.2in;

RAMECK TUYISENGEIJONATHAN_AS 18
border: 4px red;
border-radius: 2px;
}
button {color: black; background: chartreuse; font-weight: bold;
font-family: serif; font-size: 0.25in}
input[type=radio] {
font-weight: bold;
font-size: 0.3in;
}
</style>

Registration for Employees:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<title>Filled_Info</title>
</head>
<body bgcolor="bisque">
<center>
<div class="myBaby">
<form action="Information.php" method="POST">
<h1>Empleyee's Registration_form</h1>

RAMECK TUYISENGEIJONATHAN_AS 19
<label for="firstname">FirstName:</label>
<input type="text" name="FirstName" step="any" pattern="[a-
zA-Z]+" required/><br><br>
<label for="lastname">LastName:</label>
<input type="text" name="LastName" step="any" pattern="[a-
zA-Z]+" required/><br><br>
<label for="phone">Tel:</label>
<input type="text" name="Tel" step="any" pattern="[0-9]+"
required/><br><br>
<label for="email">E-mail:</label>
<input type="text" name="E-mail" step="any" pattern="[a-zA-
Z0-9/\.@-]+" required/><br><br>
<label for="country">Select Your Country where you live to
day↧</label><br>
<select name="country">
<option>Rwanda</option>
<option>Tanzania</option>
<option>Kenya</option>
<option>Burundi</option>
<option>DRC</option>
<option>South Sudan</option>
</select>
<br><br>
<label for="password">Password:</label>
<input type="password" name="password" step="any"
required/><br><br>
<button type="submit" name="go">Submit</button>
</form>
RAMECK TUYISENGEIJONATHAN_AS 20
<?php
if (isset($_POST['go'])) {
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Tel = $_POST['Tel'];
$Email = $_POST['E-mail'];
$country = $_POST['country'];
$password = $_POST['password'];
echo "<br><table border='3'>";
echo "<tr><th colspan='2'>You've been submitted the following
Information:</th></tr>";
echo "<tr><th>FirstName:</th><td>$FirstName.</td></tr>";
echo
"<tr><th>LastName:</th><td>$LastName.</td></tr>";
echo "<tr><th>PhoneNumber:</th><td>$Tel.</td></tr>";
echo "<tr><th>E-mail
Address:</th><td>$Email.</td></tr>";
echo
"<tr><th>Live_Country:</th><td>$country.</td></tr>";
echo
"<tr><th>Lock_Security:</th><td>$password.</td></tr>
";
echo "</table>";
echo "<h3>Thank you for your login confirmation ";
echo "</h3>";
}
?>
RAMECK TUYISENGEIJONATHAN_AS 21
</div></center>
</body>
</html>
<style>
.myBaby {
background: lightcyan;
text-align: center;
align-content: center;
align-items: center;
border: 4px inset darkblue;
border-radius: 0.2rem;
box-sizing: border-box;
box-shadow: 2px 4px 2px 4px palegreen;
margin: 12px 12px 12px;
width: 75%;
}
label {
color: black;
font-size: 0.2in;
font-weight: bold;
font-style: italic;
font-family: Arial,sans-serif;
text-shadow: 1px 1px gold;
float: inline;
RAMECK TUYISENGEIJONATHAN_AS 22
letter-spacing: 2px;
}
input[type=text],input[type=password] {
color: black;
background: ;
font-family: monospace;
font-weight: bolder;
font-size: 0.2in;
border:none;
border-top: 3px dashed black;
border-left: 3px double black;
border-radius: 2px;
width: 50%;
height: auto;

}
button {
color: white;
background: limegreen;
border: none;
font-family: "Mongolian Baiti";
font-size: 0.2in;
border-radius: 3px;
}
RAMECK TUYISENGEIJONATHAN_AS 23
table {
border-color: black;
border-block-start: inset;
border-block-color: goldenrod;
width: 100%;
background: navajowhite;
}
th:hover {
background: palegreen;
color: purple;
font-weight: bold;
font-size: 0.2in;
}
td:hover{
background: black;
color: whitesmoke;
font-family: Arial,sans-serif;
font-weight: bold;
font-size: 0.19in;
}

</style>

RAMECK TUYISENGEIJONATHAN_AS 24

You might also like