Exp 5
Exp 5
Exp 5
PHP
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP can create, open,
read, write, delete, and close files on the server, collect form data, add, delete, modify data in your database.
Set Up PHP
3. if...elseif...else statement - executes different codes for more than two conditions.Syntax:
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if first condition is false and this
condition is true;
} else {
code to be executed if all conditions are false;
}
PHP Loops
In PHP, we have the following loop types:
1. while - loops through a block of code as long as the specified condition is true.Syntax:
while (condition is true) {
code to be executed;
}
Example :
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
2. do...while - loops through a block of code once, and then repeats the loop as long as thespecified condition is true.
Syntax:
do {
code to be executed;
} while (condition is true);
Example :
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
Syntax:
function functionName() {
code to be executed;
}
Note: A function name must start with a letter or an underscore. Function names are NOTcase-sensitive.
Example :
<?php
function writeMsg() {echo
"Hello world!";
}
Programs :
Program 1: Normal page
<!DOCTYPE html>
<html>
<head>
<title>Sign Up</title>
<script>
function ValidateText() {var
username="neha"; var
password="123";
// alert("hello");
}
else{
if (document.getElementById("password").value.trim()=="") {
// console.log("test");
alert("Please Enter Your Password");return
false;
}
else{
if (document.getElementById("t1").value.trim()=="") {
// console.log("test");
alert("Please Enter Your Username ");return
false;
}
}
}
if (document.getElementById("t1").value.trim()!=username) {
alert("Incorrect Username!!!");
// document.getElementById("t2").innerHTML="Invalid Username!!!"
}
if (document.getElementById("t1").value.trim()==username &&
document.getElementById("password").value.trim()==password ) {
window.location.replace("home.html")}};
function reset(params) {
}
</script>
</head>
<body>
<div class="nav text-light">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
<a href="#">Blogs</a>
</div>
<div class="container">
<div class="row justify-content-center">
</tr>
</table>
</div>
<footer class="footer">
<div class="text-center">
<p class="date text-danger" id="date"></p>
</div>
<script>
document.getElementById("date").innerHTML = Date();
</script>
</footer>
</div>
</div>
</body>
</html>
Output:-
var username=document.getElementById("username").value.trim();var
password=document.getElementById("password").value.trim();
}
if(username == "")
{
alert(" username is required ");return
false;
}
</script>
<style>
#c1{
background-color: rgb(192, 153, 153);
width:1500px;
height:50px;
}
#c1 a{
float:left;
color: rgb(0, 0, 0);
}
#c1 a:hover{
background-color: cyan;
color: black;}</style>
</head>
</html>
Output:
Program 3:
<?php require_once('config.php'); ?> ucwords($user['firstname'].' '.$user['lastname']) :
<!DOCTYPE html> ""; ?>.</h1>
<html lang="en" class="" style="height: auto;"> <h3><?php echo stripslashes($_settings-
>info('welcome_message')) ?></h3>
<?php require_once('inc/header.php') ?>
<hr />
<body>
<ul class="social">
<li><a target="_blank" href="<?php
<!-- Header
echo $contact['facebook'] ?>"><i class="fa fa-
facebook"></i></a></li>
==================================================
<li><a target="_blank" href="<?php
--> echo $contact['twitter'] ?>"><i class="fa fa-
<header id="home"> twitter"></i></a></li>
<li><a target="_blank"
<nav id="nav-wrap"> href="mailto:<?php echo $contact['email'] ?>"><i
class="fa fa-google-plus"></i></a></li>
<a class="mobile-btn" href="#nav-wrap" <li><a target="_blank" href="<?php
title="Show navigation">Show navigation</a> echo $contact['linkin'] ?>"><i class="fa fa-
<a class="mobile-btn" href="#" title="Hide linkedin"></i></a></li>
navigation">Hide navigation</a> </ul>
</div>
<ul id="nav" class="nav"> </div>
<li class="current"><a
class="smoothscroll" href="#home">Home</a></li> <p class="scrolldown">
<li><a class="smoothscroll" <a class="smoothscroll" href="#about"><i
href="#about">About</a></li> class="icon-down-circle"></i></a>
<li><a class="smoothscroll" </p>
href="#resume">Resume</a></li>
<li><a class="smoothscroll" </header> <!-- Header End -->
href="#portfolio">Works</a></li>
<li><a class="smoothscroll"
href="#testimonials">Testimonials</a></li>
<!-- About Section
</ul> <!-- end #nav -->
==================================================
</nav> <!-- end #nav-wrap --> -->
<?php <section id="about">
$u_qry = $conn->query("SELECT * FROM users where id
= 1"); <div class="row">
foreach($u_qry->fetch_array() as $k => $v){
if(!is_numeric($k)){ <div class="three columns">
$user[$k] = $v;
}
<img class="profile-pic" src="<?php
} echo validate_image("avatar") ?>" alt="" />
$c_qry = $conn->query("SELECT * FROM contacts");
while($row = $c_qry->fetch_assoc()){ </div>
$contact[$row['meta_field']] = <div class="nine columns main-col">
$row['meta_value'];
} <h2>About Me</h2>
// var_dump($contact['facebook']); <style>
?> #about_me *{
<div class="row banner"> color:#7A7A7A !important;
<div class="banner-text"> }
<h1 class="responsive-headline">I'm </style>
<?php echo isset($user) ? <div id="about_me"><?php include
"about.html"; ?></div> <!-- Education
---------------------------------------------
<div class="row"> -- -->
<div class="row education">
<div class="columns contact-
details"> <div class="three columns header-col">
<h1><span>Education</span></h1>
<h2>Contact Details</h2> </div>
<p class="address">
<span><?php echo $contact['address'] <div class="nine columns main-col">
?></span><br> <?php
<span><?php echo $contact['mobile'] $e_qry = $conn->query("SELECT * FROM
?></span><br> education order by year desc, month desc");
<span><?php echo while($row = $e_qry->fetch_assoc()):
$contact['email'] ?></span> ?>
</p> <div class="row item">
Marks
Obtained