PHP Phpmyadmin Database App
PHP Phpmyadmin Database App
c.
d. Open a web browser then type: http://localhost/phpmyadmin
e. If access denied error is encountered, do the following: (If no error, proceed to Step i.)
Page 1 of 9
======================================================================================================
Objectives:Creating a simple PHP Database Application namedGUESTBOOK_DB.
Overview:
In this Activity, youneed to create a database GUESTBOOK_DB and3 PHP files.
1. guestbook.php
2. addguestbook.php
3. viewguestbook.php
STEPS:
6.
7. Then Click Go (far right)
8. Open SQL tab then click Clear button. Then, type the below SQL statement.
Page 2 of 9
9. Once done typing, click Go (far right)
10. Click STRUCTURE tab to see the table structure (GUESTBOOK).
11.
==================================================================================================
STEP2: Create the file guestbook.php via Notepad++ (or any text editor)
Page 3 of 9
<!DOCTYPE HTML>
<HTML>
<HEAD><TITLE>My Guest Book PHP file</TITLE></HEAD>
<BODY>
<BODY>
</HTML>
Note: Save the file in XAMPP/htdocs folder
Page 4 of 9
Then open a web browser, then type, http://localhost/guestbook.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="me"; // Mysql password - if needed make this blank ""
$db_name="guestbook_db"; // Database name
$tbl_name="guestbook"; // Table name
// Check connection
if (!$conn) {
die("Connection to server failed!".mysqli_connect_error());
}
echo "Connected successfully!";
//$db = mysqli_select_db($conn,"$db_name");
// variable declaration
$datetime=date("y-m-d h:i:s"); //date time
$name = ($_POST["name"]); //name
$email = ($_POST["email"]); // email
$comment = ($_POST["comment"]); //comment
$sql="INSERT INTO $tbl_name(name, email, comment, datetime) VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysqli_query($conn,$sql);
else {
echo "ERROR";
}
mysqli_close($conn);
?>
Page 5 of 9
TO add new user in the database,
1. Type in the web browser: http://localhost/phpmyadmin/server_privileges.php
2. In User accounts tab, Click Add user account.
3. In User name, type me. In Password type, me. In Re-type, type me. Click Check All in Global
Page 6 of 9
STEP 4: Create file viewguestbook.php
<!DOCTYPE HTML>
<HTML>
<HEAD><TITLE>My Guest Book PHP file</TITLE></HEAD>
<BODY>
<?php
// Check connection
if (!$conn) {
die("Connection to server failed!".mysqli_connect_error());
}
//$db = mysqli_select_db($conn,"$db_name");
$result = mysqli_query($conn,$sql);
while($rows=mysqli_fetch_array($result)){
?>
<?php
}
mysqli_close($conn);//close database
?>
<BODY>
</HTML>
Once the 3 PHP files are created, open guestbook.php in the web browser then try to insert at least 10 records.
Start playing around on the Guestbook PHP database application.
Note : Feel free to modify your web design and other content. Squeeze your creative juices!!!
TODelete a record, open http://localhost/phpmyadmin. Then, select Database tab. Select a database
to open (e.g. guestbook_db) – double click to open.
Select SLQ tab then type SELECT * FROM GUESTBOOK ->(this is to view the records)
Then, Click Go.
The Browse tab will be opened where in the added list of records is displayed.
Page 8 of 9
You can delete a record if needed. Click the red minus sign before Delete.
Page 9 of 9