select query in php mysql with example

Select query in php mysql with example

In previous  PHP post we learn to establish connection between PHP web application and MySQL database system. In this PHP tutorial we will learn to select a data from myql database with php form example.

Here, we design simple PHP form with a textbox and a button control. Here we select a data from database and display on webpage while click the select button.In a textbox we input integer id value then the Id wise record will be displayed on result screen.

PHP form Example for Select data

<title>PHP MySQL connection example</title>

<form method="post">
Enter Rcord ID : <input type="text" name="id"><br/>
<input type="submit" value="SELECT" name="Submit1"> <br/>

$username = "username";
$password = "password";
$hostname = "localhost"; 

//connection to the mysql database,
$dbhandle = mysqli_connect($hostname, $username, $password,$database);

$result = mysqli_query($dbhandle, "SELECT ID, Name, City FROM StudentMst where ID=".$_POST["id"] );
$result = mysqli_query($dbhandle, "SELECT ID, Name, City FROM StudentMst" );

//fetch tha data from the database 
while ($row = mysqli_fetch_array($result)) {
echo "ID:" .$row{'ID'}." Name:".$row{'Name'}." City: ". $row{'City'}."<br>";
//close the connection

The result of above php form example :

PHP MySQL Example for select data

Leave a Reply

Your email address will not be published. Required fields are marked *