SlideShare a Scribd company logo
1 of 21
PHP & MySQL
Lab Manual
SSGS DEGREE COLLEGE
Prepared
By
D. SULTHAN BASHA
Lecturer in Computer Science
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 1
1........
<html>
<head> <title> This is php program to initialize variables</title>
</head>
<Body bgcolor = "green">
<h2>
<?php
$name = "sulthan";
$age = 29;
print "Your Name: $name.<BR>";
print " Your Age: $age.<BR>";
?>
</h2>
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 2
2.........
<html>
<body bgcolor="sky blue">
<h3>
<form method="post">
How many numbers you want?
<input type="number" name="number"/><br>
<input type="submit" value="print"/>
</form>
<?php
$num=$_POST['number'];
for($i=1;$i<=$num;$i++)
{
echo "$i ";
}
?>
</h3>769
287/
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 3
3.......
<html>
<body>
<form method="post">
Enter first number:
<input type = "number" name = "number1"/><br><br>
Enter second number:
<input type = "number" name = "number2"/><br><br>
<input type = "submit" name = "submit" value="Add"/>
</form>
<?php
if(isset($_POST['submit']))
{
$number1 = $_POST['number1'];
$number2 = $_POST['number2'];
$sum = $number1+$number2;
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 4
echo "the sum of $number1 and $number2 is $sum";
}
?>
</body>
</html>
4.........
<?php
$num = 25;
if($num%2==0)
{
echo "$num is Even number";
}
else{
echo "$num is Odd number";
}
?>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 5
5.......
<?php
$num = 25;
if($num<100)
{
echo "$num is Less than 100";
}
?>
6.......
<?php
$i=10;
while($i>=1)
{
echo "$i<br>";
$i--;
}
?>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 6
7.........
<html>
<head>
<style>
.error{color:#FF0000;}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$nameErr=$emailErr=$genderErr=$websiteErr="";
$name=$email=$gender=$comment=$website="";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
if(empty($_POST["name"])){
$nameErr="Name is required";
}
else
{
$name=test_input($_POST["name"]);
// check if name only contains letters and whitespace
if(!preg_match("/^[a-zA-Z]*$/",$name)) {
$nameErr="Only letters and white space allowed";
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 7
}
}
if(empty($_POST["email"])) {
$emailErr="Email is required";
} else {
$email=test_input($_POST["email"]);
// check if e-mail address is well-formed
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr="Invalid email format";
}
}
if(empty($_POST["website"])) {
$website="";
} else {
$website=test_input($_POST["website"]);
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
if(!preg_match("/b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0-
9+&@#/%=~_|]/i",$website)) {
$websiteErr ="Invalid URL";
}
}
if(empty($_POST["comment"])) {
$comment="";
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 8
} else {
$comment=test_input($_POST["comment"]);
}
if(empty($_POST["gender"])) {
$genderErr= "Gender is required";
} else {
$gender=test_input($_POST["gender"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:<input type="text" name ="name" value="<?php echo $name;?>">
<span class="error">*<?php echo $nameErr;?></span>
<br><br>
E-mail:<input type="text" name="email" value="<?php echo $email;?>">
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 9
<span class="error">*<?php echo $emailErr;?></span>
<br><br>
Website:<input type="text" name="website" value="<?php echo $website;?>">
<span class="error">*<?php echo $websiteErr;?></span>
<br><br>
Comment:<textarea name="comment" rows="5" cols="40"><?php echo
$comment;?></textarea>
<br><br>
Gender:
<input type="radio" name="gender"<?php if(isset($gender) && $gender=="female") echo
"checked";?>
value="female">Female
<input type="radio" name="gender"<?php if(isset($gender) && $gender=="male") echo
"checkede";?>
value="male">Male
<input type="radio" name="gender" <?php if(isset($gender) && $gender=="other") echo
"checked";?>
value="other">Other
<span class="error">*<?php echo $genderErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo"<h2>Your Input:</h2>";
echo "$name";
echo "<br>";
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 10
echo "$email";
echo "<br>";
echo "$website";
echo "<br>";
echo "$comment";
echo "<br>";
echo "$gender";
?>
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 11
8..........
<html>
<head>
<?php
$servername = "localhost:3306";
$username ="avinash";
$password = "avinash";
$dbname = "avinash";
// Create connection
$conn = new mysqli($servername,$username,$password,$dbname);
// Check connection
if($conn->connect_error) {
die("Connection failed:". $conn->connect_error);
}
$sql = "SELECT productid, productname, price,MFD FROM product";
$result = $conn->query($sql);
if($result->num_rows>0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<br>".$row["productid"].$row["productname"].$row["price"].$row["MFD"]."<br >";
}
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 12
} else {
echo "0 results";
}
$conn->close();
?>
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 13
9..........
<?php
$servername="localhost:3306";
$dbname="avinash";
$username="avinash";
$password="avinash";
//Create connection
$conn=mysqli_connect($servername,$dbname, $username,$password);
//Check connection
if(!$conn)
{
die("Connection failed:".mysql_error());
}
echo "connected successfully";
$sql = "SELECT * FROM `product`";
$result=mysqli_query($conn,$sql);
if($result)
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 14
{
$num_of_rows=mysqli_num_rows($result);
echo "<br>ProductID ProductName Price MFD"."<br>";
while($row = $result->fetch_assoc())
{
// echo"<br>ProductID:".$row["productid"]."ProductName: ".$row["productname"]."Price:
".$row//["price"]."MFD: ".$row["MFD"]."<br>";
printf("%d",$row["productid"]);
printf("%s",$row["productname"]);
printf("%d",$row["price"]);
printf("%s",$row["MFD"]);
echo ".<br>";
}
printf("<br>Result Set %d rows n", $num_of_rows);
}
else{
printf("Could Not Retrieve", mysqli_error($mysqli));
}
mysqli_free_result($result);
mysqli_close($conn);
?>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 15
10........
<!DOCTYPE html>
<html>
<body>
<?php
echo "The time is".date("h:i:sa");
?>
</body>
</html>
11............
<?php
$name="AVINASH";
$age="19";
print "your name: $name.<BR>";
print "your age: $age.<BR>";
?>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 16
12......
<?php
for($i=1;$i<=10;$i++)
{
echo"$i<br>";
}
?>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 17
13.........
<html>
<body>
<form method="post">
<input type="text" name="text"/><br>
<input type="submit" Value="submit"/><br>
</form>
<?php
$str=$_POST['text'];
if($str==strrev($str))
{
echo "$str is a palindrome";
}
else
{
echo "$str is not a palindrome";
}
?>
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 18
14..........
<html>
<body>
<?php
echo strrev("Hello WQorld");
?>
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 19
15...........
<html>
<body>
<?php
$favcolor = "blue";
switch ($favcolor)
{
case "red":
echo "Your favorite color is red !";
break;
case "blue":
echo "Your favorite color is blue !";
break;
case "green":
echo "Your favorite color is green !";
break;
default;
echo"your favorite color is neither red,blue,nor green!";
}
?>
</body>
</html>
PHP & MySQL
B.Sc(C.S) – Cluster [C2] Page 20
16........
<html>
<body>
<?php
$t=date("h:m:s,d:m:y");
echo"<P>The hour(of the server) is ".$t;
echo"and will give the following message:</p>";
if($t<"10")
{
echo"Have a good morning!";
}
elseif($t<"20")
{
echo "Have a good day!";
}
else
{
echo"Have a good night!";
}
?>
</body>
</html>

More Related Content

What's hot

PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1Kanchilug
 
Date difference[1]
Date difference[1]Date difference[1]
Date difference[1]shafiullas
 
PHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post MethodsPHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post MethodsAl-Mamun Sarkar
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in phpherat university
 
Database Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlDatabase Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlAl-Mamun Sarkar
 
PHP記帳網頁教材(第一頁是空白的)
PHP記帳網頁教材(第一頁是空白的)PHP記帳網頁教材(第一頁是空白的)
PHP記帳網頁教材(第一頁是空白的)TaiShunHuang
 
Gem christmas calendar
Gem christmas calendarGem christmas calendar
Gem christmas calendarerichsen
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample PhpJH Lee
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnSandro Zaccarini
 
TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !Matheus Marabesi
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angularDavid Amend
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionNur Fadli Utomo
 
Php web backdoor obfuscation
Php web backdoor obfuscationPhp web backdoor obfuscation
Php web backdoor obfuscationSandro Zaccarini
 

What's hot (19)

TICT #13
TICT #13TICT #13
TICT #13
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1
 
Date difference[1]
Date difference[1]Date difference[1]
Date difference[1]
 
PHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post MethodsPHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post Methods
 
Yql && Raphaël
Yql && RaphaëlYql && Raphaël
Yql && Raphaël
 
Ubi comp27nov04
Ubi comp27nov04Ubi comp27nov04
Ubi comp27nov04
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Insertcustomer
InsertcustomerInsertcustomer
Insertcustomer
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
Database Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlDatabase Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and Mysql
 
PHP記帳網頁教材(第一頁是空白的)
PHP記帳網頁教材(第一頁是空白的)PHP記帳網頁教材(第一頁是空白的)
PHP記帳網頁教材(第一頁是空白的)
 
Gem christmas calendar
Gem christmas calendarGem christmas calendar
Gem christmas calendar
 
C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample Php
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
 
TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !
 
Javascript
JavascriptJavascript
Javascript
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angular
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan Session
 
Php web backdoor obfuscation
Php web backdoor obfuscationPhp web backdoor obfuscation
Php web backdoor obfuscation
 

Similar to SULTHAN's - PHP MySQL programs

Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivityMouli Chandira
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus Ramberg
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxCynthiaKendi1
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Michael Schwern
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011John Ford
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kianphelios
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 

Similar to SULTHAN's - PHP MySQL programs (20)

PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Tutorial_4_PHP
Tutorial_4_PHPTutorial_4_PHP
Tutorial_4_PHP
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 

More from SULTHAN BASHA

Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdfSulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdfSULTHAN BASHA
 
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_ScienceSulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_ScienceSULTHAN BASHA
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN BASHA
 
SULTHAN's ICT-2 for UG courses
SULTHAN's ICT-2 for UG coursesSULTHAN's ICT-2 for UG courses
SULTHAN's ICT-2 for UG coursesSULTHAN BASHA
 
SULTHAN's - Data Structures
SULTHAN's - Data StructuresSULTHAN's - Data Structures
SULTHAN's - Data StructuresSULTHAN BASHA
 
SULTHAN's - ICT-1 for U.G courses in India
SULTHAN's - ICT-1 for U.G courses in IndiaSULTHAN's - ICT-1 for U.G courses in India
SULTHAN's - ICT-1 for U.G courses in IndiaSULTHAN BASHA
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN BASHA
 

More from SULTHAN BASHA (7)

Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdfSulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
 
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_ScienceSulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
 
SULTHAN's ICT-2 for UG courses
SULTHAN's ICT-2 for UG coursesSULTHAN's ICT-2 for UG courses
SULTHAN's ICT-2 for UG courses
 
SULTHAN's - Data Structures
SULTHAN's - Data StructuresSULTHAN's - Data Structures
SULTHAN's - Data Structures
 
SULTHAN's - ICT-1 for U.G courses in India
SULTHAN's - ICT-1 for U.G courses in IndiaSULTHAN's - ICT-1 for U.G courses in India
SULTHAN's - ICT-1 for U.G courses in India
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notes
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

SULTHAN's - PHP MySQL programs

  • 1. PHP & MySQL Lab Manual SSGS DEGREE COLLEGE Prepared By D. SULTHAN BASHA Lecturer in Computer Science
  • 2. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 1 1........ <html> <head> <title> This is php program to initialize variables</title> </head> <Body bgcolor = "green"> <h2> <?php $name = "sulthan"; $age = 29; print "Your Name: $name.<BR>"; print " Your Age: $age.<BR>"; ?> </h2> </body> </html>
  • 3. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 2 2......... <html> <body bgcolor="sky blue"> <h3> <form method="post"> How many numbers you want? <input type="number" name="number"/><br> <input type="submit" value="print"/> </form> <?php $num=$_POST['number']; for($i=1;$i<=$num;$i++) { echo "$i "; } ?> </h3>769 287/ </body> </html>
  • 4. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 3 3....... <html> <body> <form method="post"> Enter first number: <input type = "number" name = "number1"/><br><br> Enter second number: <input type = "number" name = "number2"/><br><br> <input type = "submit" name = "submit" value="Add"/> </form> <?php if(isset($_POST['submit'])) { $number1 = $_POST['number1']; $number2 = $_POST['number2']; $sum = $number1+$number2;
  • 5. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 4 echo "the sum of $number1 and $number2 is $sum"; } ?> </body> </html> 4......... <?php $num = 25; if($num%2==0) { echo "$num is Even number"; } else{ echo "$num is Odd number"; } ?>
  • 6. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 5 5....... <?php $num = 25; if($num<100) { echo "$num is Less than 100"; } ?> 6....... <?php $i=10; while($i>=1) { echo "$i<br>"; $i--; } ?>
  • 7. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 6 7......... <html> <head> <style> .error{color:#FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr=$emailErr=$genderErr=$websiteErr=""; $name=$email=$gender=$comment=$website=""; if($_SERVER["REQUEST_METHOD"]=="POST") { if(empty($_POST["name"])){ $nameErr="Name is required"; } else { $name=test_input($_POST["name"]); // check if name only contains letters and whitespace if(!preg_match("/^[a-zA-Z]*$/",$name)) { $nameErr="Only letters and white space allowed";
  • 8. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 7 } } if(empty($_POST["email"])) { $emailErr="Email is required"; } else { $email=test_input($_POST["email"]); // check if e-mail address is well-formed if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr="Invalid email format"; } } if(empty($_POST["website"])) { $website=""; } else { $website=test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if(!preg_match("/b(?:(?:https?|ftp)://|www.)[-a-z0-9+&@#/%?=~_|!:,.;]*[-a-z0- 9+&@#/%=~_|]/i",$website)) { $websiteErr ="Invalid URL"; } } if(empty($_POST["comment"])) { $comment="";
  • 9. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 8 } else { $comment=test_input($_POST["comment"]); } if(empty($_POST["gender"])) { $genderErr= "Gender is required"; } else { $gender=test_input($_POST["gender"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation Example</h2> <p><span class="error">* required field</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name:<input type="text" name ="name" value="<?php echo $name;?>"> <span class="error">*<?php echo $nameErr;?></span> <br><br> E-mail:<input type="text" name="email" value="<?php echo $email;?>">
  • 10. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 9 <span class="error">*<?php echo $emailErr;?></span> <br><br> Website:<input type="text" name="website" value="<?php echo $website;?>"> <span class="error">*<?php echo $websiteErr;?></span> <br><br> Comment:<textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> Gender: <input type="radio" name="gender"<?php if(isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender"<?php if(isset($gender) && $gender=="male") echo "checkede";?> value="male">Male <input type="radio" name="gender" <?php if(isset($gender) && $gender=="other") echo "checked";?> value="other">Other <span class="error">*<?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php echo"<h2>Your Input:</h2>"; echo "$name"; echo "<br>";
  • 11. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 10 echo "$email"; echo "<br>"; echo "$website"; echo "<br>"; echo "$comment"; echo "<br>"; echo "$gender"; ?> </body> </html>
  • 12. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 11 8.......... <html> <head> <?php $servername = "localhost:3306"; $username ="avinash"; $password = "avinash"; $dbname = "avinash"; // Create connection $conn = new mysqli($servername,$username,$password,$dbname); // Check connection if($conn->connect_error) { die("Connection failed:". $conn->connect_error); } $sql = "SELECT productid, productname, price,MFD FROM product"; $result = $conn->query($sql); if($result->num_rows>0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<br>".$row["productid"].$row["productname"].$row["price"].$row["MFD"]."<br >"; }
  • 13. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 12 } else { echo "0 results"; } $conn->close(); ?> </body> </html>
  • 14. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 13 9.......... <?php $servername="localhost:3306"; $dbname="avinash"; $username="avinash"; $password="avinash"; //Create connection $conn=mysqli_connect($servername,$dbname, $username,$password); //Check connection if(!$conn) { die("Connection failed:".mysql_error()); } echo "connected successfully"; $sql = "SELECT * FROM `product`"; $result=mysqli_query($conn,$sql); if($result)
  • 15. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 14 { $num_of_rows=mysqli_num_rows($result); echo "<br>ProductID ProductName Price MFD"."<br>"; while($row = $result->fetch_assoc()) { // echo"<br>ProductID:".$row["productid"]."ProductName: ".$row["productname"]."Price: ".$row//["price"]."MFD: ".$row["MFD"]."<br>"; printf("%d",$row["productid"]); printf("%s",$row["productname"]); printf("%d",$row["price"]); printf("%s",$row["MFD"]); echo ".<br>"; } printf("<br>Result Set %d rows n", $num_of_rows); } else{ printf("Could Not Retrieve", mysqli_error($mysqli)); } mysqli_free_result($result); mysqli_close($conn); ?>
  • 16. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 15 10........ <!DOCTYPE html> <html> <body> <?php echo "The time is".date("h:i:sa"); ?> </body> </html> 11............ <?php $name="AVINASH"; $age="19"; print "your name: $name.<BR>"; print "your age: $age.<BR>"; ?>
  • 17. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 16 12...... <?php for($i=1;$i<=10;$i++) { echo"$i<br>"; } ?>
  • 18. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 17 13......... <html> <body> <form method="post"> <input type="text" name="text"/><br> <input type="submit" Value="submit"/><br> </form> <?php $str=$_POST['text']; if($str==strrev($str)) { echo "$str is a palindrome"; } else { echo "$str is not a palindrome"; } ?> </body> </html>
  • 19. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 18 14.......... <html> <body> <?php echo strrev("Hello WQorld"); ?> </body> </html>
  • 20. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 19 15........... <html> <body> <?php $favcolor = "blue"; switch ($favcolor) { case "red": echo "Your favorite color is red !"; break; case "blue": echo "Your favorite color is blue !"; break; case "green": echo "Your favorite color is green !"; break; default; echo"your favorite color is neither red,blue,nor green!"; } ?> </body> </html>
  • 21. PHP & MySQL B.Sc(C.S) – Cluster [C2] Page 20 16........ <html> <body> <?php $t=date("h:m:s,d:m:y"); echo"<P>The hour(of the server) is ".$t; echo"and will give the following message:</p>"; if($t<"10") { echo"Have a good morning!"; } elseif($t<"20") { echo "Have a good day!"; } else { echo"Have a good night!"; } ?> </body> </html>