Get Data From MySQL Using PHP


In this article I explain Get data from MySQL using jQuery with PHP. I am using a simple HTML form and a JavaScript function with a MySQL table for creating this phenomenon. Such that the user enters a name and fetch your table user enter name correct or not.  


First of all, create a new database and table in your MySQL and insert some data. Such as:


Then create a HTML form for displaying the data, such as:



<title>Untitled Document</title>

<script type="text/javascript" src=""></script>

<script type="text/javascript">

    function get() {


        $.post('data.php', { name: },

        function (output) {






<body bgcolor="#B096FE">


<form name="form" method="post">

<input type="text" name="name">

<input type="button" value="get" onclick="get();">

//show your data in div section though 'id'

<div id="age"></div>






In this form I provided a JavaScript function in the head section.


This is a PHP script file. In this file is your database connection.



$con = mysql_connect("localhost","root","");

if (!$con)


  die('Could not connect: ' . mysql_error());


$name= mysql_real_escape_string($_POST['name']);

$age= mysql_query("select age from vinod.people where name='$name'");



echo "please enter name!";




echo "name does not exist!";




echo "$name age is $age";



You can use this article just like that. When enter a blank text box then a message like this is shown:


When the user enters the wrong name then a message like this is shown:


When the user enters the correct name then a message like this is shown: