select option in php using database

I will show you how to add data into select option by fetching data from database. its quite simple. select option is mostly used for registrations & other major activities & forms. select option is useful.

create database named premal. add 1 table named location_country with 2 fields. 1 is for id autoincrement & name.

premal katigar

After that some data into database.

Now get following Code.

<select name="location" id="location">
$query="select name from location_country";
 <option value="NULL">SELECT</option>
 <option value="<?php $row[0] ?>"><?php echo $row[0] ?></option>


how to connect database in php

It’s quite Simple to connect to the database of php that is MY_SQL.

Simple Create a new php file with database.php.



localhost is host name & root is user name.


Above sentence is for selecting database my database is psk & we have to pass one variable that is of connection. I have pass $p.

mysql_query() is used for execute query. I have used for update query.


Congo. You got connect with database.