Professional Documents
Culture Documents
WebBasedApplicationDevelopmentUsing
PHP
(22619)
Semester– VI
(CO/CW/CM/IF)
Government Polytechnic,Gondia
Fulchur road, Gondia
CERTIFICATE
WebBasedApplicationDevelopmentusingPhp(22619)fortheacademicyear
Seal
Instiitute
KUNAL TAMRAJ HARINKHEDE (1912420306)
S. Approx.
Unit
Hrs.
No.
Required
a. Install and configure PHP, web server,ivIYSQL
b. Write n program to print “Welcome toPHI°’.
c. Write a simplePi-11* program using expressions and 1 02*
operators.
2 Write a PHP proSr am tndcmonsiraie the use of Decision
making control structuresusing-
a. If statcmcnt I 02*
b, If-else stniernent
c. Switch statcmcnt
3 Write a PHP program to deiiionstrate the use of Looping
structures using-
a. While statement, b. Do-while statement c,For statement
d. Foreach statement
4 Write a PHP program for creating and manipulating-
a. Indexedarray 02
b. Associativearray
c. Multidimensionalarray
5 a. Write a PHP programto-
i. Calculate length ofstring.
ii, Count the number of words in string -without using
string functions.
›I 2-
b. Write n simple PHP program to demonstrate use ofvarious
built-in gtringfuncLons.
6 Write a simple PHP program to demonstrate use of Simple
function and Parameterized function. ›I 02
7 Write a simple I°HP program to crcate PDF dncument by using
II 02
graphics concepts.
8 Write a PHP program to-
a. Inherit members of super class insubclass.
III 02*
b. Create constructor to initialize object ofclass
--by using object oriented concepts
9 Write a simplG PHP program on Introspection and 02
III
Serialization.
10 Design a web page using following form controls: IV 02*
a. Text box, b. Radio button. c. Check box, d. Burtons
11 Design a web pnge using following form controls: IV O2*
a. 11st box, b. Combo box, c. Hidden field box
12 Develop web page with data validation. IV 02’
13 Write simple PHP program to -
n. Set cookies and read it. IV 02*
b. Demonstrate session Management.
14 Write a simple PHP program for sending and receiving plain iV -
text message (e-mail).
15 Develop a simple application to-
a. Enter data into database V 02*
b, Retrieve and present data from database.
16 Develop a simple application to Updnte, Delete table datn V 02*
database.
Total 32
KUNAL TAMRAJ HARINKHEDE (1912420306)
I. Relevant ProgramOutcomes(POs)
Basic Knowledge: Apply knowledge of basic mathematics, sciences and basic engg
to solve the broad based computer enggproblem.
Discipline Knowledge: Apply computer engg discipline – specific knowledge to
solve core computer engg relatedproblems.
Experiments and practice: plan to perform experiments and practices to use the
results to solve broad based computer enggproblems.
Engineering tools: Apply relevant computer technologies and tools with an
understanding of thelimitations.
Individual and team work: function effectively as a loader and team member in
diverse/ multidisciplinaryteams.
Communication: communicate effectively in oral and writtenform.
Life-long learning: engage in independent and life-long learning activities in the
context of technological changes in the computer engg field and alliedindustry.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
In the web browser, visit Apache Friends and download XAMPP installer.
During the installation process, select the required components like MySQL, FileZilla ftp
server, PHP, phpMyAdmin or leave the default options and click the Next button.
Uncheck the Learn more about bitnami option and click Next button.
Choosetherootdirectorypathtosetupthehtdocsfolderforourapplications.Forexample ‘C:\
xampp’.
Click the Allow access button to allow the XAMPP modules from the Windows firewall.
After the installation process, click the Finish button of the XAMPP Setup wizard.
Now the XAMPP icon is clearly visible on the right side of start menu. Show or Hide can
be set by using the control panel by clicking on the icon.
KUNAL TAMRAJ HARINKHEDE (1912420306)
To start Apache and MySql, just click on the Start button on the control panel.
Note:SupposeApacheisnotstarting,itmeanssomeotherserviceisrunningatport80.In this
case, stop the other service temporarily and restartit.
Making server request: Open your web browser and check whether the XAMPP service
has properly installed or not. Type in the URL: http://localhost. If you are able to see the
default page for XAMPP, you have successfully installed your XAMPP Server.
To Check if PHP is Working: All the website realted files are organized in a folder called
htdocs and then run index.php file by using http://localhost/index.php or http://localhost.
Note: For every new website or application, its always better to create a different folder
inside htdocs, to keep it organized and avoid confusion.
For example, if we create a folder geeksforgeeks and then create a file nameed as
‘helloWorld.php’.
All the contents related to it are put inside the folder ‘geeksforgeeks’. So the root ‘URL’ of the
websitewillbe‘http://localhost/geeksforgeeks/’.Soanyhomepageisaccessedbytypingtheroot URL
in the browser. To see the output, just type‘http://localhost/geeksforgeeks/helloWorld.php’.
Generally web servers look for index file (landing page) namely index.html or
index.phpintherootofthewebsitefolder.Goto/xampp/htdocs/folderandcreateafilewith.php
extension (test.php) and type or copy the below code and saveit.
KUNAL TAMRAJ HARINKHEDE (1912420306)
<?
phpphpi
nfo();
Note: In XAMPP, the configuration files of Apache, MySQL, PHP are located in C:\Program Files\
xampp. For any configuration file changes, you need to restart Apache and MySQL.
<?php
echo"Welcome to Php";
?>
Output
KUNAL TAMRAJ HARINKHEDE (1912420306)
<?php
Output' $a = 2, $b = 4;
echo$a."\n";
echo$b."\n";
echo"Sum of both values:", $a + $b;
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VI. Conclusion:
Successfully Installed XAMPP Web Server on desktop and executed first program.
VII. AssessmentScheme
Practical no 2:
Write a PHP program to demonstrate the use of decision making control
structures using –
a. If statement
b. If-else statement
c. Switch statement
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
if ($t < "20") {
echo "Have a good day!";
}
?>
b) If-else statement
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
c) Switch statement
<?php
$favcolor = "red";
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!";
}
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Used the decision making control
structures if ,if-else and switch statement.
VIII. AssessmentScheme
Practical no 3:
KUNAL TAMRAJ HARINKHEDE (1912420306)
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
Sr. Name of resource Specification Quantity Remarks
No. /material
1 Hardware Approx. Windows 10 Intel i5, As per Batch
Computer System 4GB RAM, 1TB HDD Size For All
2 Software/ Website XAMPP Web Server, Notepad++ 1 Practical’s
of PHP
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
b) Do-while statement
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
c) For statement
<?php
for ($x = 0; $x <= 100; $x+=10) {
echo "The number is: $x <br>";
}
?>
d) Foreach statement
<?php
$age = array("Peter"=>"35", "Pranav"=>"37", "Joe"=>"43");
VII. Conclusion:
The code is run successfully and we get required output. Used the different types of loops
like while, do-while, for, and foreach statement.
VIII. AssessmentScheme
S Performance Indicators Weightage in
No. %
1. Completion of given Task. 25%
2. Correctness of given Task. 50%
3. Answer to Sample Questions. 15%
4. Submit Report in Time. 10%
Total 100%
Practical no 4:
Write a php program for creating and manipulating –
a) Indexed array
b) Associative array
c) Multidimensional array
I. Relevant ProgramOutcomes (POs)
Basic Knowledge: Apply knowledge of basic mathematics, sciences and basic engg
to solve the broad based computer enggproblem.
Discipline Knowledge: Apply computer engg discipline – specific knowledge to
solve core computer engg relatedproblems.
Experiments and practice: plan to perform experiments and practices to use the
results to solve broad based computer enggproblems.
Engineering tools: Apply relevant computer technologies and tools with an
understanding of thelimitations.
Individual and team work: function effectively as a loader and team member in
diverse/ multidisciplinaryteams.
Communication: communicate effectively in oral and writtenform.
Life-long learning: engage in independent and life-long learning activities in the
context of technological changes in the computer engg field and alliedindustry.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
b) Associative array
<?php
$age = array("Pranav"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Pranav is " . $age['Pranav'] . " years old.";
?>
c) Multidimensional array
<?php
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Used the php program for creating
and manipulating –
a) Indexed array
b) Associative array
c) Multidimensional array
VIII. AssessmentScheme
Practical no 5:
a) Write a php program –
1. Calculate length of string.
2. Count the numbers of words in string –without using string
functions.
b) Write a simple PHP program to demonstrate use of various built in
string functions.
I. Relevant ProgramOutcomes (POs)
Basic Knowledge: Apply knowledge of basic mathematics, sciences and basic engg
to solve the broad based computer enggproblem.
Discipline Knowledge: Apply computer engg discipline – specific knowledge to
solve core computer engg relatedproblems.
Experiments and practice: plan to perform experiments and practices to use the
results to solve broad based computer enggproblems.
Engineering tools: Apply relevant computer technologies and tools with an
understanding of thelimitations.
Individual and team work: function effectively as a loader and team member in
diverse/ multidisciplinaryteams.
Communication: communicate effectively in oral and writtenform.
Life-long learning: engage in independent and life-long learning activities in the
context of technological changes in the computer engg field and alliedindustry.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
// Function call
$len = get_num_of_words($str);
</body>
</html>
VII. Conclusion:
The code run successfully and we get required output. Used the different string functions.
VIII. AssessmentScheme
Practical no 6:
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
VII. Conclusion:
The code run successfully and we get required output. Used the function and parameterized
function.
VIII. AssessmentScheme
Practical no 7:
Write a simple php program to create pdf document by using graphics concepts.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
Sr. Name of resource Specification Quantity Remarks
No. /material
1 Hardware Approx. Windows 10 Intel i5, As per Batch
Computer System 4GB RAM, 1TB HDD Size For All
2 Software/ Website XAMPP Web Server, Notepad++ 1 Practical’s
of PHP
KUNAL TAMRAJ HARINKHEDE (1912420306)
$pdf=newFPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Let’s say that you have downloaded and extracted the FPDF package inside a folder
called ~/public_html/fpdf/. Create a new PHP file called toPDF.php inside the same folder
and insert the above code. Save the file and try to access it through your browser:
http://yourdomain.com/fpdf/toPDF.php
Upon execution, the PHP script will generate a PDF file in your browser.
VII. Conclusion:
The code run successfully and we get required output. Used the php program to create pdf
document by using graphics concepts.
KUNAL TAMRAJ HARINKHEDE (1912420306)
VIII. AssessmentScheme
Practical no 8:
KUNAL TAMRAJ HARINKHEDE (1912420306)
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
<?php
class Fruit {
public $name;
public $color;
public function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
public function intro() {
echo"The fruit is {$this->name} and the color is {$this->color}.";
}
}
// Strawberry is inherited from Fruit
class Strawberry extends Fruit {
public function message() {
echo"Am I a fruit or a berry? ";
}
}
$strawberry = new Strawberry("Strawberry", "red");
$strawberry->message();
$strawberry->intro();
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
b) Create constructor to initialize object of class –by using object oriented concepts.
<?php
class Fruit {
public $name;
public $color;
function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
function get_name() {
return $this->name;
}
function get_color() {
return $this->color;
}
}
$apple = new Fruit("Apple", "red");
echo $apple->get_name();
echo "<br>";
echo $apple->get_color();
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Used the inheritance and constructor
in program.
VIII. AssessmentScheme
Practical no 9:
Write a simple php program on Introspection and serialization.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
?>
2. Serialzation
<?php
$a=array('Shivam','Rahul','Vilas');
$s=serialize($a);
print_r($s);
$s1=unserialize($s);
echo"<br>";
print_r($s1);
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Used the introspection and
serialization
VIII. AssessmentScheme
Practical no 10:
KUNAL TAMRAJ HARINKHEDE (1912420306)
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
Sr. Name of resource Specification Quantity Remarks
No. /material
1 Hardware Approx. Windows 10 Intel i5, As per Batch
Computer System 4GB RAM, 1TB HDD Size For All
2 Software/ Website XAMPP Web Server, Notepad++ 1 Practical’s
of PHP
KUNAL TAMRAJ HARINKHEDE (1912420306)
<?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";
}
}
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 = "";
} 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;
}
?>
KUNAL TAMRAJ HARINKHEDE (1912420306)
<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
?>
</body>
</html>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Used Text
box,Radiobutton,Checkbox,Buttons form controls to Design a web page .
VIII. AssessmentScheme
Practical no 11:
Design a web page using following form controls:
a) List box
b) Combo box
c) Hidden field box
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
KUNAL TAMRAJ HARINKHEDE (1912420306)
V. Additional Resourcesrequired
VII. Conclusion:
The code run successfully and we get required output.
VIII. AssessmentScheme
Practical no 12:
Develop a web page with data validation.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
Sr. Name of Specification Quantity Remarks
No. resource
/material
1 Hardware Approx. Windows 10 Intel i5, As per
Computer System 4GB RAM, 1TB HDD Batch For All
Size Practical’s
2 Software/ Website XAMPP Web Server, Notepad+ 1
+ of PHP
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Developed the webpage with
validation.
KUNAL TAMRAJ HARINKHEDE (1912420306)
VIII. AssessmentScheme
Practical no 13:
Write a simple program to -
a) Set cookies and read it.
b) Demonstrate session management
I. Relevant ProgramOutcomes (POs)
Basic Knowledge: Apply knowledge of basic mathematics, sciences and basic engg
to solve the broad based computer enggproblem.
Discipline Knowledge: Apply computer engg discipline – specific knowledge to
solve core computer engg relatedproblems.
Experiments and practice: plan to perform experiments and practices to use the
results to solve broad based computer enggproblems.
Engineering tools: Apply relevant computer technologies and tools with an
understanding of thelimitations.
Individual and team work: function effectively as a loader and team member in
diverse/ multidisciplinaryteams.
Communication: communicate effectively in oral and writtenform.
Life-long learning: engage in independent and life-long learning activities in the
context of technological changes in the computer engg field and alliedindustry.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
Sr. Name of Specification Quantity Remarks
No. resource
/material
1 Hardware Approx. Windows 10 Intel i5, As per
Computer System 4GB RAM, 1TB HDD Batch For All
Size Practical’s
2 Software/ Website XAMPP Web Server, Notepad+ 1
+ of PHP
KUNAL TAMRAJ HARINKHEDE (1912420306)
Output:
Sorry, cookie is not found!
</body>
</html>
KUNAL TAMRAJ HARINKHEDE (1912420306)
VII. Conclusion:
The code run successfully and we get required output. Used the a simple program to -
a) Set cookies and read it.
b) Demonstrate session management
VIII. AssessmentScheme
Practical no 14:
KUNAL TAMRAJ HARINKHEDE (1912420306)
Write a simple PHP program for sending and receiving plain text message
(e-mail).
I. Relevant ProgramOutcomes (POs)
Basic Knowledge: Apply knowledge of basic mathematics, sciences and basic engg
to solve the broad based computer enggproblem.
Discipline Knowledge: Apply computer engg discipline – specific knowledge to
solve core computer engg relatedproblems.
Experiments and practice: plan to perform experiments and practices to use the
results to solve broad based computer enggproblems.
Engineering tools: Apply relevant computer technologies and tools with an
understanding of thelimitations.
Individual and team work: function effectively as a loader and team member in
diverse/ multidisciplinaryteams.
Communication: communicate effectively in oral and writtenform.
Life-long learning: engage in independent and life-long learning activities in the
context of technological changes in the computer engg field and alliedindustry.
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
Sr. Name of Specification Quantity Remarks
No. resource
/material
1 Hardware Approx. Windows 10 Intel i5, As per
Computer System 4GB RAM, 1TB HDD Batch For All
Size Practical’s
2 Software/ Website XAMPP Web Server, Notepad+ 1
+ of PHP
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
?>
OR
<?php
extract($_POST);
if(isset($sendmail))
{
$subject ="Mail Function in PHP";
$from="info@phptpoint.com";
$message =$name."".$mobile."".$query;
$headers = "From:".$from;
mail($email,$subject,$message,$headers);
<html>
<body>
<?php
$to_email = "pranavwagh955@gmail.com";
$subject = "Simple Email Test PHP pranav";
$body = "Hi, This is Test Email Send by PHP program ";
$headers = "From: pranav2001@gmail.com";
VII. Conclusion:
KUNAL TAMRAJ HARINKHEDE (1912420306)
VIII. AssessmentScheme
Practical no 15:
KUNAL TAMRAJ HARINKHEDE (1912420306)
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
Sr. Name of Specification Quantity Remarks
No. resource
/material
1 Hardware Approx. Windows 10 Intel i5, As per
Computer System 4GB RAM, 1TB HDD Batch For All
Size Practical’s
2 Software/ Website XAMPP Web Server, Notepad+ 1
+ of PHP
Filename: insert.php
KUNAL TAMRAJ HARINKHEDE (1912420306)
<!DOCTYPE html>
<html>
<head>
<title>Insert Page page</title>
</head>
<body>
<center>
<?php
// servername =>localhost
// username => root
// password => empty
// database name => staff
$conn = mysqli_connect("localhost", "root", "", "staff");
// Check connection
if($conn === false){
die("ERROR: Could not connect. "
. mysqli_connect_error());
}
// Taking all 5 values from the form data(input)
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$gender = $_REQUEST['gender'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];
// Performing insert query execution
// here our table name is college
$sql = "INSERT INTO college VALUES ('$first_name',
'$last_name','$gender','$address','$email')";
if(mysqli_query($conn, $sql)){
echo"<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
echo nl2br("\n$first_name\n $last_name\n "
. "$gender\n $address\n $email");
} else{
echo"ERROR: Hush! Sorry $sql. "
. mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
KUNAL TAMRAJ HARINKHEDE (1912420306)
?>
</center>
</body>
</html>
KUNAL TAMRAJ HARINKHEDE (1912420306)
or
https://drive.google.com/file/d/1XLQm51pp9jhP9IxiTdM-RpYqxL9PyB43/view?usp=drivesdk
VII. Conclusion:
Practical 15 is all used in my micro project the link is given above for results.
Develop a simple application to -
Enter data into database
Retrieve and present data from database.
VIII. AssessmentScheme
Practical no 16:
KUNAL TAMRAJ HARINKHEDE (1912420306)
IV. Precautions
1. Handle computer systemcarefully.
2. Note down the exact output for eachcase.
V. Additional Resourcesrequired
1 <?php
2 $host='localhost';
3 $username='root';
4 $password='';
5 $dbname= "mydb";
6 $conn=mysqli_connect($host,$username,
7 $password,"$dbname");
8 if(!$conn)
9 {
1 die('Could not Connect MySql
0 Server:'.mysql_error());
1 }
1 ?>
Then, Create a new file named insert.php and add the following code into insert.php:
1 <?php
2 include_once'db.php';
3
4
5 $firstname= 'Hello';
6 $lastname= 'Test';
7 $mobile= '9874561230';
8
9 $sql= "INSERT INTO users
1 (firstname,lastname,mobile)
0 VALUES
1 ('$name','$email','$mobile')";
1
1 if(mysqli_query($conn, $sql)) {
2 echo"New record has been added
1 successfully !";
3 } else{
1 echo"Error: ". $sql.":-".
4 mysqli_error($conn);
1 }
5 mysqli_close($conn);
1
6 ?>
1
7
1
8
1
KUNAL TAMRAJ HARINKHEDE (1912420306)
Note that, The SQL INSERT statement will insert record in MySQL database using PHP
function.
Then, create a new file named Select.php and add the following code into selete.php:
1
2
3
4 <?php
5 include_once'db.php';
6
7 $sql= "SELECT * FROM users";
8
9 $query= mysqli_query($conn,$sql);
1
0 if(!$query)
1 {
1 echo"Query does not
1 work.".mysqli_error($conn);die;
2 }
1
3 while($data=
1 mysqli_fetch_array($query))
4 {
1 echo"Id = ".$data['id']."<br>";
5 echo"Firstname = ".
1 $data['firstname']."<br>";
6 echo"Lastname = ".
1 $data['lastname']."<br>";
7 echo"Mobile = ".
1 $data['mobile']."<br><hr>";
8 }
1 ?>
9
2
0
Note that, The SQL SELECT statement will SELECT record FROM MySQL database
using PHP function.
KUNAL TAMRAJ HARINKHEDE (1912420306)
If you want to select limited records from MySQL database, you can use LIMIT clause
with SQL query like following:
Or, if you want to fetch record with ascending or descending order. So, you can use ASC
OR DESC with SQL query.
Now, you can modify database table records using SQL “UPDATE “ statement query.
So, Create a new file named Update.php and add the following code into update.php:
<?php
1
2 include_once'db.php';
3
4 $sql= "UPDATE users SET firstname = 'Hello',lastname =
5 'Test',mobile = '9874561230' WHERE id=1 ";
6
7 $query= mysqli_query($conn,$sql);
8 if(!$query)
9 {
10 echo"Query does not
11 work.".mysqli_error($conn);die;
12 }
13 else
14 {
15 echo"Data successfully updated";
16 }
17
18
?>
If you want to delete some records or all records from database, you can
use DELETE SQL statement with PHP.
So, Create a new file named Delete.php and add the following code into delete.php:
1 <?php
2 include_once'db.php';
3
4 $sql= "DELETE FROM users WHERE
5 userid='". $_GET["userid"] . "'";
6
7 if(mysqli_query($conn, $sql)) {
8
echo"Record deleted
KUNAL TAMRAJ HARINKHEDE (1912420306)
9
1
0 successfully";
1
1 } else{
1
2 echo"Error deleting record: ".
1 mysqli_error($conn);
3 }
1 mysqli_close($conn);
4 ?>
1
5
or
VII. Conclusion:
Developed a simple application to update, delete table data from database. Is provide in
drive link.
VIII. AssessmentScheme