L6 XAMPP PHP and Databases
L6 XAMPP PHP and Databases
Browse 6
Web
r Server
5 2
MySQL 4
PHP
Server Engine
WHAT IS PHP?
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with
multiple parameters.";
?>
EXAMPLE
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
echo "<h2>$txt1</h2>";
echo "Study PHP at $txt2<br>";
echo $x + $y;
?>
EXAMPLE - PRINT
<?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
EXAMPLE - PRINT
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
print "<h2>$txt1</h2>";
print "Study PHP at $txt2<br>";
print $x + $y;
?>
XAMPP
Install XAMPP to the root directory: C:\XAMPP
Launch XAMPP control panel and start the
following services:
MySql
Apache
Open your web browser and enter in the URL box:
http://localhost
RUNNING XAMPP ERROR: OBJECT NOT FOUND
Go to XAMPP Control Panel
Click on config (APACHE)
Select Apache(httpd.conf)
Search for “DocumentRoot”
Look at the path pointing to the htdocs folder.
e.g "C:/xampp/htdocs“
Or "C:/Users/xampp/htdocs"
YOUR FIRST PHP APPLICATION
Navigate to “C:\XAMPP\htdocs”
Create a project folder called HelloPHP
Inside the folder create a file with a .php
extension called Hello World.
YOUR FIRST PHP APPLICATION
Write the
following code
into the file:
YOUR FIRST PHP APPLICATION
While (condition)
{
Statements;
}
DATE DISPLAY
or
MONTH, DAY & DATE FORMAT SYMBOLS
FUNCTIONS
Index.php
WORKING WITH FORMS
• php2.php
EXERCISE 1
Using a while loop, draw the following
pattern onto the browser using a PHP
script.
WORKING WITH DATABASES
FROM THE SCREEN:
Click on phpMyadmin
Click on Databases
Enter db name (myDB) and click on create
Click on the database name(to the left) and enter a table name
Students, specify 3 columns for it and click on Go.
Enter 3 column names (name, Surname and RegNo) of type
VarChar and length 20 and click on Save
Click on SQL,delete the query that’s appearing and enter the
following query:
Click on Go.
1. VIEWING DATABASE CONTENT IN BROWSER
BROWSER
Go to browser
Type in the URL Box:
localhost/TableStudents.php
The following page should appear in browser:
VIEWING DB FROM BROWSER
2. INSERTING VALUES INTO DATABASE FROM
BROWSER
INSERTING VALUES INTO DB FROM BROWSER
Command Syntax:
Question:
Question:
b) Edit the form on the previous page so that the user can
click on a button labelled Edit.
When this button is clicked, a modal appears containing
textboxes that allows the user to edit the information in
the database.