TILOTTAMA SECONDARY SCHOOL
CREATING A SIMPLE APP USING
PHPAND SQL
RECOMMENDATION
This is to certify that the report entitled “ CREATING A SIMPLE
APP USING PHP ” has been submitted by NIKIT SHRESTHA as
part of the partial fulfillment of the practical examination for
Computer in Grade XII. This document involves the detailed study of
PHP, showcasing the student’s throughout understanding of the
subject matter. This work has not been submitted for any other
academic practical examination or institution. Based on the quality of
this project, I whole heartily recommend this document as fulfilling the
practical requirements for the Grade XII Computer Examination.
SUPERVISOR
SHANKHAR BHANDARI
Department of Computer
Tilottama Secondary School
Yogikuti,Rupandehi
CERTIFICATE OF APPROVAL
This is to certify that the report entitled “ CREATING A
SIMPLE APP USING PHP ” submitted by Mr./Mrs./Ms.
NIKIT SHRESTHA has been accepted for the partial
fulfillment of practical examination of Computer in Grade
XII. This project work has not been submitted by any other
school or institution previously for award of Grade XII.
This certificate is issued upon the given project work.
Supervisor
Mr.Shankhar Bhandari
Department of Computer
Tilottama Secondary School
ACKNOWLEDGEMENTS
Firstly, I would express my heartfelt gratitude to my respected
Mr.Shankhar Bhandari sir for his regular guidance,
suggestion and inspiration throughout my work. Again, its my
pleasure to express my sincere gratitude to my friends for their
guidance, valuable suggestion, cooperation and completion of
my report. I would like to express my heartfelt thank to the
teachers.
Supervisor
Mr.Shankhar Bhandari
Department of Computer
Tilottama Secondary School
TABLE OF CONTENT
S. N. Content Area Contents Page No.
1. Front Page Project Name, Name of student I
2. Recommendation Recommendation II
3. Certificate of III
Approval
Certificate of Approval
4. Acknowledgements IV
Acknoledgements
5. About PHP, How to run a PHP
Introduction to program and Examples of PHP
PHP program for arithmetic 4
calculation and data types
Introduction to About SQL, Creating Database
6. SQL using PHP using mysqli 7
command and Basic SQL
Queries
Overview of Project, Requirements,
Creating an Easy Database, Flowchart, Data flow
7. App using SQL 10
diagram, Source Code, Testing,
and PHP Implementation
Er. Tej Prasad Aryal, Kriti’s
Computer Science 2079, 20
8. Biliography wikipidea.org,
hashnode.com/shoomankhatri
1.
INTRODUCTION TO PHP
LEARNING OUTCOMES
1. Introduction to PHP
2. What is PHP?
3. How to run a PHP program in your
computer?
You’ll need to review
1. Basic Programming Concepts with
variables, operators, string etc.
2. HTML and CSS
3. Basic JavaScript
4. Basic Web Development Skills
PHP
The PHP (Hypertext Preprocessor) is a programming language that
allows web developers to create dynamic content that interacts with
databases. It is generally used for developing web based software
applications. It was initially named as Personal Home Page.
PHP is a widely used, open source scripting language.
PHP is free to download and use.
PHP is easy to learn and write.
PHP helps to connect databases to create a dynamic content.
PHP files have a file extension of “.php”.
HOW TO RUN A PHP PROGRAM?
Step 1: To write a code you need a text editor like Notepad++, Virtual Studio
Code, Sublime Text, CoffeeCup, EditPlus, gedit, Dreamwaver etc. Download
your favourite text editor.
Step 2: PHP requires a Server to run the code. PHP runs fine on Apache Web
Server. You need to install XAMPP in your computer from the internet.
Step 3: Start the Apache and MySQL services from XAMPP Control Panel.
Step 4: Write the PHP code in your favorite editor.
Step 5: Save the file location to : C:\xampp\htdocs\Filename.php.
Step 6: Open the web browser and type: “http://localhost/Filename.php/”. Step
7: The code runs in the server.
Step 8: Enjoy your PHP program.
Page No. 4
EXAMPLES
index.php
<html>
<head>
<title>PHP</title>
<body>
<?php
$a=5; // decimal number
s$b=-4; // a negetive number
$c=4.45; // float
$book=“Physics”; //a string
echo “a=$a <br> b=$b <br>”;
echo “c=$c <br> Book=$book”;
?>
</body>
</html>
Index.php
<!DOCTYPE html>
<html>
<head>
<title>Sum of Two Numbers</title>
</head>
<body>
<form method="post">
Enter First Number: <input type="number" name="num1" required><br><br>
Enter Second Number: <input type="number" name="num2"
required><br><br>
<input type="submit" name="submit" value="Calculate Sum">
</form>
<?php
if(isset($_POST['submit'])){
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$sum = $num1 + $num2;
echo "<h3>Sum:
$sum</h3>";
}
?>
Page No. 5
2.
INTRODUCTION TO SQL
LEARNING OUTCOMES
1. Introduction to SQL
2. Making SQL Queries
3. Creating SQL Database with PHP
You’ll need to review
4. Relational Database
5. Database basics primary key, foreign
key etc.
6. PHP
SQL
SQL (Structured Query Language) is a standardized
programming language used to manage and manipulate relational
databases. It is used to perform tasks such as:
1. Querying: Retrieving data from one or more tables in
a database.
2. Updating: Modifying existing data in the database.
3. Inserting: Adding new records (data) to the database.
4. Deleting: Removing data from the database.
5. Defining Data Structures: Creating, modifying, or deleting
tables and other database objects.
6. Access Control: Managing permissions to control access to
the database and its objects.
MAKING SQL QUERIES
1. To create Database:
CREATE DATABASE Database_Name;
2. To create Table:
CREATE TABLE table_name(column_name column_type);
3. To insert Data:
INSERT INTO table_name(field1,field2,..............,fieldN)
VALUES(value1,value2,....................,valueN);
4. To Select Data:
SELECT field1,field2,…….,fieldN
FROM table_name1,table_name2,…..
[WHERE Clause]
[LIMIT N]
5. To Delete Data:
DELETE FROM table_name [WHERE Clause]
Page No. 9
CREATING SQL DATABASE WITH PHP
PHP mysqli_connect() Function:
The mysqli_connect() function opens a new connection to the
MySQL server.
Syntax:
mysqli_connect(host, username, password, dbname, port, socket);
Parameter Description
Host Specifies a host name or an IP address
Username Specifies the MySQL username
Password Specifies the MySQL password
dbname Specifies the default database to be used
Port Optional.Specifies the port number to attempt
Socket Optional.
Example
<?php
function OpenCon()
{
$dbhost = “localhost”;
$dbuser = “root”;
$dbpass = “”;
$db = “database_name”;
$conn = new mysqli_connect($dbhost, $dbuser, $dbpass, $db) or die(“Connect
failed: “. $conn -> error);
feturn conn;
}
function CloseCon($conn)
{
$conn -> close():
}
?>
Page No. 10
3.
CREATING AN APP
LEARNING OUTCOMES
1. How to connect PHP with SQL
2. PHP program and SQL commands
3. How to create an easy app with PHP
and SQL
4. Design, Testing, Coding and
Implementation
You’ll need to review
1. PHP
2. SQL
3. Creating SQL database with PHP
CREATING AN APP FOR TRIP FORM
Creating a simple website to collect trip-related data using PHP and SQL is
a great way to learn web development. Here's an overview and step-by-
step guide on how to approach this project. The app will include a form
where users can submit their trip details, and the data will be stored in a
database.
Overview of the Project
Goal: Create a form that collects information about trips to the US
(Name, Age, Gender, Email and Phone) and stores the data in a
MySQL database.
Technology Stack:
1. Front end: HTML, CSS, and optionally JavaScript for form
validation or enhancements.
2. Back end: PHP for handling form submission and processing.
3. Database: MySQL to store data.
Requirements
1. Operating System
Windows XP, Windows 7, Windows 8, Windows 10 or later, Mac.
2. Processor
Dual Core @ 2.33GHz or faster x86-compatible
3. RAM : 2GB
4. Hard Drive Space : 1 GB Available Space
5. Video Card : Intel HD Graphics 4000 or better
6. DirectX : 11.0c
7. Web Server : XAMPP
8. Web Browser : Google Chrome, Microsoft Edge, Opera GX etc.
9. Text Editor : Visual Studio Code, NotePad++ etc.
Page No. 12
Database
Here’s a table to store the input data from users in the front end in SQL:
ID Task Completed
1. Homework Pending
2. Breakfast Completed
Page No. 13
FLOWCHART
START
USER OPENS THE
WEB APP
User Inputs
a choice
UPDATE TOGGLE
SAVE
SAVES
DATA
TO SQL
DISPLAY TO
DO LIST
END
13
Page No. 14
Index.php
<html>
<title>To Do List</title>
</head>
<body>
<header>
<h1> EASY APP </h1>
</header>
<form action="adddata.php" method="post">
<div class="main">
<label for="task"> Task: </label><br>
<input type="text" name="task" id="task" required><br><br>
<input type="submit" value="Save">
</div>
</form>
<hr color="Blue">
<h2> List of Tasks </h2>
<table>
<tr>
<th> Task</th>
<th> Status</th>
<th> Action</th>
</tr>
<?php
include 'db.php';
$sql = "SELECT * FROM xyz;";
$result = mysqli_query($conn, $sql);
if($result){
while($row = mysqli_fetch_assoc($result)){
$id = $row['id'];
$task = $row['task'];
$completed = $row['completed'] ? 'Completed' : 'Pending';
?>
<tr>
<td><?php echo $task ?></td>
<td><?php echo $completed ?></td>
<td>
<a href="edit.php?id=<?php echo $id; ?>"> Update</a>
<a href="delete.php?id=<?php echo $id; ?>"> Delete</a>
<a href="toggle.php?id=<?php echo $id; ?>"> Toggle Status</a>
</td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>
Page No. 15
db.php adddata.php
<?php <?php
$host = "localhost"; include 'db.php';
$user = "root"; $task = $_POST['task'];
$pass = ""; $sql = "INSERT INTO xyz (task, completed)
$dbname = "abc"; VALUES ('$task', 0)";
$conn = mysqli_connect($host, $user, $pass, $result = mysqli_query($conn, $sql);
$dbname) or die("Connection failed"); if($result){
?> header('Location: index.php');
}
?>
style.css
body {
background-color: edit.php
black; color: aqua;
font-family: Arial, sans- <body>
serif; text-align: center; <header>
} <h1> <center> EASY APP <center> </h1>
header { </header>
padding: 20px; <h2> Update Task </h2>
font-size: <?php
24px; include 'db.php';
} $id = $_GET['id'];
form { $sql = "SELECT * FROM xyz WHERE id = '$id'";
margin: 20px auto; $result = mysqli_query($conn, $sql);
padding: 10px; if($result){
background: #222; $row = mysqli_fetch_assoc($result);
width: 50%; $taskname = $row['task'];
border-radius: 5px; }
} ?>
input[type="text"], input[type="submit"] { <form action="editaction.php" method="post">
padding: 10px; <div class="main">
margin: 10px; <label for="task"> Task: </label><br>
border: none; <input type="text" name="task"
border-radius: id="task" value = "<?php echo $taskname ?>"
5px; required><br><br>
} <input type="hidden" name="id"
input[type="submit"] id="id" value ="<?php echo $id ?>"
{ background: required><br><br>
aqua; color: <input type="submit" value="Update">
black; </div>
font-weight: bold; </form>
cursor: pointer; </body>
}
table {
toodle.php
margin: auto; <?php
width: 60%; include 'db.php';
border-collapse: collapse; $id = $_GET['id'];
} $sql = "UPDATE xyz SET completed = NOT
th, td { completed WHERE id = $id";
padding: 10px; mysqli_query($conn, $sql);
border: 1px solid aqua; header('Location: index.php');
} ?>
a {
color: aqua;
text-decoration: none;
padding: 5px;
Page No. 16
delete.php editaction.php
<?php <?php
include 'db.php';
$id = $_POST['id'];
$task = $_POST['task'];
include 'db.php'; $sql = "UPDATE xyz SET task = '$task' WHERE id =
$id = $_GET['id']; '$id';";
$sql = "UPDATE xyz SET completed $result = mysqli_query($conn, $sql);
= NOT completed WHERE id = $id"; if($result){
mysqli_query($conn, $sql); header('location:index.php');
}
?>
SQL
CREATE DATABASE IF NOT EXISTS abc;
USE abc;
CREATE TABLE IF NOT EXISTS xyz (
id INT AUTO_INCREMENT PRIMARY KEY,
task VARCHAR(255) NOT NULL,
completed TINYINT(1) DEFAULT 0
);
CODE DETAILS
This PHP-based To-Do List App allows users to manage tasks with a simple
CRUD (Create, Read, Update, Delete) system. The app consists of an index page
(index.php) that displays tasks fetched from a MySQL database (xyz table) and
provides options to add, edit, delete, and toggle task completion. The backend
scripts (adddata.php, editaction.php, delete.php, and toggle.php) handle these
operations via MySQL queries. The app uses aqua-colored text on a black
background for a sleek, modern look, styled through CSS (style.css). Forms and
tables are structured for a smooth user experience, making task management
efficient and intuitive.
The database connection (db.php) ensures communication with the MySQL
database, storing task names and their completion status (0 for pending, 1 for
completed). When a user adds a task, it is stored as pending, and they can later
update the task name, mark it as complete, or delete it. The edit page
(edit.php) retrieves the task's details for modification, and toggle.php updates its
status dynamically. This structure ensures a simple yet functional task manager
that can be expanded with more features, such as user authentication or due dates.
Page No. 17
TESTING
The interface of this app looks as shown aside.
To add tasks you need to put your task inside
the input box and save the data. The data gets
stored in SQL(Server) and shows up on the
screen as shown in the figure below.
You can add multiple tasks at a time
and you can also edit or delete or
change the status of tasks if you have
completed it. It makes us to work more
efficently.
The tasks can also be edited by clicking
on the update button.
The data is stored in SQL in form of a
database in phpMyAdmin server.
Page No. 18
IMPLEMENTATION
First of all create a GitHub id and then go to the
create repositories button. Then create a repository
and give it a name for eg. To Do List and make it
public.
Then select all the files from your folder where
the project is stored and upload it to GitHub.
After you create a repository, go to settings and
then the pages and select the main branch as
shown in figure aside. This uploads your website
and anyone can access your Easy App by URL.
Refresh the page and the URL is found as shown
in the figure.
Page No. 19
NATURE OF PROJECT
The project focuses on developing a simple web application using PHP and SQL,
specifically a To-Do List App. The primary objective is to create a dynamic web-
based system that allows users to manage tasks efficiently. Users can add new
tasks, update existing ones, delete tasks, and toggle their completion status. The
application leverages PHP as the back-end scripting language to handle user
inputs and process database operations, while SQL is used to store and manage
task-related data.
This project follows a structured approach to web development, covering various
aspects such as front end design, server-side scripting, and database
integration. The front end is built using HTML, CSS, and JavaScript, ensuring
a user-friendly interface, while PHP interacts with a MySQL database to store
and retrieve data dynamically. The project demonstrates fundamental CRUD
(Create, Read, Update, Delete) operations, which are essential for database-
driven applications.
Furthermore, the implementation involves setting up a local development
environment using XAMPP, which provides an Apache web server and MySQL
database support. The project also includes a step-by-step guide on how to
connect PHP with SQL, write database queries, and test the application. To ensure
accessibility, the project recommends hosting the code on GitHub, enabling
others to access the app via a public URL.
Overall, this project serves as an educational tool for students learning web
development. It introduces essential programming concepts related to PHP and
SQL, making it a practical and hands-on experience. The simplicity of the app
makes it a great starting point for anyone looking to understand how web
applications interact with databases
The link for this project is
“https://github.com/NikitStha/To-Do-list”
Page No. 20
BILIOGRAPHY
Er. Tej Prasad Aryal, Kriti’s Computer Science 2079(Revised)
Wikipedia.org
hashnode.com/sumankhatri