[go: up one dir, main page]

0% found this document useful (0 votes)
142 views6 pages

PHP Tutorial Step by Step

This document provides steps to set up a local PHP development environment using XAMPP on Windows. It includes instructions to download and install XAMPP, start the Apache and MySQL servers, check that they are running, and set the document root. It then demonstrates creating a basic "Hello World" PHP page and shows how to create a database, table, HTML form to insert data, PHP script to insert into the database, and output the stored data in a table. The goal is to provide an end-to-end example of developing a basic PHP/MySQL application locally.

Uploaded by

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

PHP Tutorial Step by Step

This document provides steps to set up a local PHP development environment using XAMPP on Windows. It includes instructions to download and install XAMPP, start the Apache and MySQL servers, check that they are running, and set the document root. It then demonstrates creating a basic "Hello World" PHP page and shows how to create a database, table, HTML form to insert data, PHP script to insert into the database, and output the stored data in a table. The goal is to provide an end-to-end example of developing a basic PHP/MySQL application locally.

Uploaded by

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

PHP TUTORIAL STEP BY STEP

1 How to download Xampp Server


A. Open Google chrome search xampp -> Go to the XAMPP website and click the
"XAMPP for Windows" download button.
B. the download is complete -> open the XAMPP installer file.
2 How to install xampp Server
a. Open my computer -> then go to download folder click xampp setup allow
permission to the setup .
b. Allow the installation to complete. This may take a few minutes depending
on your system.
3 Setup and Start Xampp Server
 Click the "XAMPP Control Panel" search for it and launch it from the start menu.
 Choose the language, And save it.
 Click the "Start" button for both Apache and MySQL.
 Apache and mysql should now display "Running" in green text.
4 Checking the root directory
 This shows the document root is set to c:/xampp/htdocs by default.
5 Checking the root directory open the browser
Search “localhost\dashbord” then click phpmyadmin
6 Creating first Site Displaying helloworld
"Created a Test Folder under XAMPP Root Directory" D:\Xampp\htdocs\test
 In the test folder, create a php file called index.php
 Add some code like:
<?php echo "Hello World!"; ?>
Example Site to
Create html form
Store the data in database
Display the contents of database

Step 1: Creating table in database


1. Create Database
2. Create Table
 Go to http://localhost/phpmyadmin in your browser. You should see the phpMyAdmin
login page.
Create new database
 On the left sidebar, click "Databases" and enter a name for your new database is name
db1. And Click "Create" button
 enter a name for your new Create table Name: user and Number of columns: 3.
 Click "GO " to create the create Table.
 A set of column name, type, length/values, index, A_I. column name
ssss(‘id”,”fname”,”lname”)
Step 2: Create a html form
 Open text editor and open a index.php file in the C:\Xampp\htdocs\test
directory.
 Write these Code.

<!DOCTYPE html>
<html>
<body>
<form action="submit.php" method="post">
First Name:<br>
<input type="text" name="firstname">
<br>
Last Name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
 Then check :
open browser search ” localhost/test/index.php/ ” .
Step 3 : Write Submite.php To insert data to database Database name:
db1 Table Name: user
 Open text editor and create a new file named submit.php in the
C:\Xampp\htdocs\test directory.
 Write these Code.

<?php
$x = $_POST['firstname'];
$y= $_POST['lastname'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db1";
//Create connection
$conn = new mysqli($servername, $username, $password,
$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT INTO `user` (`fname`, `lname`) VALUES ('$x', '$y')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close(); ?>
 Then check :
open browser search ” localhost/test/index.php/ ” .
 Then typing insert data (First name: & Last name: ) and Click the
"Submit " button .

HOW TO CHECK INSERT DATA IN PHPMYADMIN


 Login to phpMyAdmin and select the database “db1”.
 Click on the table name “user”.
 To verify, click on the 'Browse' tab.
 You should now see the inserted row displayed in the table.
 Click the editing icon (pencil symbol) for that row.
 This will open the row details where you can see the inserted
values.
 Review each column to confirm the data was inserted correctly.
 Click 'Close' once you are done reviewing.

Step 4 : Display Database Content on Website


 Write these Code.
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width:100%;
background color: blue;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<?php
$x = $_POST['firstname'];
$y= $_POST['lastname'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db1";
//Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT INTO `user` (`fname`, `lname`) VALUES ('$x', '$y')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql = "SELECT id, fname, lname FROM `user`";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
//output data of each row
echo "<table>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td> id: " . $row["id"] . "</td><td> Name: " .
$row["fname"] . " " . $row["lname"] . "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
</body>
</html>
 Then check : open browser search ” localhost/test/index.php/ ” .
 Then typing insert data (First name: & Last name: ) and Click the
"Submit " button .

You might also like