Reader Level:

Get Data From MySQL Using PHP

By Vinod Kumar on Mar 06, 2013
In this article I explain Get data from MySQL using jQuery with 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:


Vinod  Kumar
Vinod Kumar

       Hi every one I am MCA qualified from IGNOU, Currently working as a Senior software Engineer at dogSpot pvt ltd gurgaon having 3+ year experience and also like web designing ... Read more



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up

Infragistics jQuery Controls