A demonstration of a HTML form that submits data to a MySQL database running on XAMPP.
- Apache
- MySQL Server
- HTML5-compatible browser
- XAMPP, running:
- Apache
- MySQL Server
- HTML5-compatible browser
You'll need the packages for MySQL (most common client is MariaDB) and Apache (known on some platforms as httpd):
# Debian/Ubuntu and compatibles:
sudo apt install mysql-client apache2
# Arch and most other distros: (Substitue in your package manager instead)
sudo pacman -S mariadb apache
Start both servers:
# Debian/Ubuntu:
sudo systemctl start apache2
sudo systemctl start mysql
# Arch and others:
sudo systemctl start httpd
sudo systemctl start mariadb
Set up MySQL:
sudo mysql -u root # root privileges are needed to create a new database and users.
CREATE DATABASE learning;
USE learning;
CREATE TABLE student_details (id text, PRIMARY KEY (id(6)), name text, surname text, cool text);
-- Password is "1337":
CREATE USER apache IDENTIFIED BY PASSWORD "*C6F8F27F2F530B7B270D641A3604424B9B404D43";
GRANT SELECT, INSERT, UPDATE ON *.* to apache;
EXIT;
Navigate to localhost:80/phpmyadmin
.
- Databases → Database name → "learning" → Create
- Create table → Name: → "student_details" → Number of columns: → 4
- Insert the following in to the console at the bottom:
CREATE TABLE student_details (id text, PRIMARY KEY (id(6)), name text, surname text, cool text);
- Ctrl+Enter
- Go to phpMyAdmin homepage
- User accounts → New → Add user account:
Field | Value |
---|---|
User name: | apache |
Host name: | % |
Password: | 1337 |
Authentication plugin: | Native MySQL Authentication |
- Global priveleges → Data → enable SELECT, INSERT, and UPDATE
- SSL → REQUIRE NONE
- Go
git clone https://github.com/toydotgame/learning-php.git; cd learning-php/
# Debian/Ubuntu and compatibles:
sudo cp -rf . /var/www/html/
# Arch and other httpd versions of Apache:
sudo cp -rf . /srv/http/
Then open your browser to localhost:80
to see the form page.
In XAMPP's Control Panel, go to the Apache Module → Actions → Config → Apache (httpd.conf), and find DocumentRoot
, set it to the directory that this repository was cloned to. i.e:
DocumentRoot "C:/Users/User/Documents/learning-php"
Then, navigate to localhost:80
in your browser to see the form page.
Login to MySQL: (password is "1337")
mysql -u apache -p learning
Show all data in the database and/or select a single entry via <student number>
:
SELECT * FROM student_details;
SELECT * FROM student_details WHERE id LIKE "<student number>";
Navigate to localhost:80/phpmyadmin
and find the student_details table (under the learning database) in the left column. Click on that and view database entries on the right.