How to Dynamically Get the Value of a Select Tag from MySQL Table Using PHP
Submitted by nurhodelta_17 on Monday, August 21, 2017 - 15:26.
Language
This tutorial will help you on how to dynamically get the value of a select tag from MySQL Table using PHP. This tutorial will not teach you on how to create a good design but rather to give you knowledge on how to create a fully functional select tag.
Creating our Database
First, we're going to create a database that contains the data that we want to show as options in our select tag. 1. Open phpMyAdmin. 2. Click databases, create a database and name it as "select". 3. After creating a database, click the SQL and paste the below code. See image below for detailed instruction.- CREATE TABLE `user` (
- `userid` INT(11) NOT NULL AUTO_INCREMENT,
- `uname` VARCHAR(50) NOT NULL,
- PRIMARY KEY (`userid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Inserting Data into our Database
Next, we insert data into our database. These are the data that we are going to show in out option. 1. Click our database "select". 2. Click SQL and paste the below code.- INSERT INTO `user` (`uname`) VALUES
- ('neovic'),
- ('leeann');
Creating our Connection
Next step is to create a database connection and save it as "conn.php". This file will serve as our bridge between our page and our database. To create the file, open your HTML code editor and paste the code below after the tag.- <?php
- // Check connection
- {
- }
- ?>
Creating our Select Tag
Lastly, we create our page to show our select tag and name it as "index.php". This page will show the select tag where options are data from our database. To create the page, open your HTML code editor and paste the code below after the tag.Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Add new comment
- 475 views