Integrating database with a website practical
Integrating database with a website practical
Purpose: Generate and execute a new database file to test and understand basic database syntax.
Computer
Windows 10 and above.
You might get a UAC warning before installation. Click OK and continue.
Select the components you want to install. If you’re planning to install a WordPress site with
XAMPP, you only need Apache, MySQL, PHP, and phpMyAdmin. I’ll check all the
components as I’d like to experiment with them later.
Choose the installation directory for XAMPP (default recommended).
Uncheck Learn more about Bitnami option. Bitnami provides all-in-one tools to install popular
open source apps on top of XAMPP. This includes add-on modules for installing Word Press too.
However, we’ll be installing it manually here.
You may be presented with a Windows Security Alert at the end of the installation. You need to
whitelist Apache HTTP Server from your Windows Defender Firewall by clicking the Allow
access button. Make sure to check the “Private networks, such as my home or work network”
option. This is very important. XAMPP won’t work if you don’t check this and click Allow access.
The XAMPP Control Panel sports a simple user interface that lists all the modules of your local
server. It allows you to Start/Stop individual modules, access their Admin area, Config files, and
Logs with just a single click. Its bottom section also displays all your actions and errors (if any).
Click the Start button beside Apache module. If everything’s set correctly, your Apache server
should start successfully under ports 83 and 443.
You can access your Apache server’s dashboard by clicking the Admin button beside it.
Alternatively, you can also reach it via http://localhost/dashboard/ URL in your browser.
Then Start the MySQL module. If you’re presented with a Windows Security Alert to whitelist
mysqld.exe, click Allow access. Like before, make sure that you’ve ticked the “Private
networks…” option.
Don’t forget to tick the “Private networks” option. You can access your phpMyAdmin dashboard
by clicking the Admin button beside MySQL module. Or you can simply go to
http://localhost/phpmyadmin/ in your browser. Here, you can manage the MariaDB (or MySQL)
databases of your web projects.
The phpMyAdmin Dashboard
This concludes the setup of XAMPP as your local development environment. It’s now ready to
host any PHP-based software (e.g. Word Press).
The best way to check whether your local server has been installed and configured correctly is to
create a PHP test page, place it in XAMPP’s local host folder, and then try accessing it via your
browser.
Let’s do that now. Create a new folder called test in your C:\xampp\htdocs\ directory. This
directory can also be accessed easily by clicking the Explorer button in XAMPP Control Panel and
then going to htdocs folder.
Create a file called test.php with the code below and place it in C:\xampp\htdocs\test folder.
<html>
<head>
<title>PHP-Test</title>
</head>
<body>
</body>
</html>
Try visiting http://localhost/test/test.php in your browser. If it displays the words “Hello World!
Welcome to WPMU DEV”, then XAMPP is successfully installed and configured on your system.
If IIS is not installed by default, you can download and install the latest version of IIS Express for
your Windows 10 or Windows 11 OS from the Microsoft website. IIS versions later than 7.0
include the new IIS Manager User interface.
5. If you plan on using integrated Windows authentication in website hosted in IIS, tick the
Windows Authentication option under Internet Information Services > World Wide Web
Services > Security as well and select OK.
1. You can now install and test your website on IIS. After installation, you will see your web
console listed in IIS Manager (inetmgr), along with a default website generated when you
enabled IIS.
Step 1: Design your Database and HTML form requirements for your web page
Filter your HTML form requirements for your contact us web page
Step 1: Filter your HTML form requirements for your contact us web page
Suppose you selected the form field Name (text input), Email (email input), Phone (number input),
and message (multi-line text). The form submit button also necessary for submitting the form. You
will get the complete form in HTML coding in step 3.
USE `db_Name`;
ALTER TABLE
Example
USE `db_contact`;
)
2b. you can use your web server applications to create the Database
Open a web browser (chrome, Firefox, edge, etc.,) and type this http://localhost/phpmyadmin/ or
http://127.0.0.1/phpmyadmin/ for open GUI for managing DB on your computer. See the xampp
screen below how it is coming.
E.g. click on the databases new link and create your db by the name “db_contact”.
Now you have to create an HTML form. For this, you need to create a working folder first and
then create a web page with the name “contact.html”. If you install xampp your working folder is
in folder this “E:\xampp\htdocs”. You can create a new folder “contact” on your local host working
folder. Create a “contact.html” file and paste the following code.
<html>
<head>
<body>
<fieldset>
<legend>Contact Form</legend>
<p>
</p>
<p>
<label for="email">Email</label>
</p>
<p>
<label for="phone">Phone</label>
</p>
<p>
<label for="message">Message</label>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
</fieldset>
</body>
</html>
Now your form is ready. You may test it in your localhost link http://localhost/contact/contact.html
For storing data in MySQL as records, you have to first connect with the DB. Connecting the code
is very simple. The mysql_connect in PHP is deprecated for the latest version therefore I used it
here mysqli_connect.
You need to place value for your localhost username and password. Normally localhost MySQL
database username is root and password blank or root. For example, the code is as below
The “db_contact” is our database name that we created before. Then you will save the file with
“contact.php”
Quality Criteria: The web page should display the output of your database.
Lap Tests
Task 1: Create database table