PHP and MySQL Code

Start typing to search for PHP and MySQL Code Snippets and Articles Search

Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
Title : Data Retrieve from Mysql using AJAX with PHP
Categories : PHP, AJAX, Date Time, Databases, MySQL
Suraj Thapaliya
Date : May 01st 2006
Grade : 3 of 5 (graded 90 times)
Viewed : 233541
File :
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.

This example is useful to those programmers who want to use ajax in php.

Tested on
Browse Name:        Opera / 8.53
Browse Name:        Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
Gecko/20060308 Firefox/
Browse Name:         Microsoft Internet Explorer / 6.0
Browse Name :        Mozilla 1.5

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <title>Get Customer Data</title>
//customer ID
$sID = $_GET["id"];
//variable to hold customer info
$sInfo = "";
//database information
$sDBServer = "your_server_name";
$sDBName = "your_database_name";
$sDBUsername = "your_user_name";
$sDBPassword = "your_password";

//create the SQL query string
$sQuery = "Select * from Customers where CustomerId=".$sID;
//make the database connection
$oLink = mysql_connect($sDBServer,$sDBUsername,$sDBPassword);
mysql_select_db($sDBName) or $sInfo = "Unable to open database";
$sInfo == '') {
$oResult = mysql_query($sQuery) and mysql_num_rows($oResult) > 0) {
$aValues = mysql_fetch_array($oResult,MYSQL_ASSOC);
$sInfo = $aValues['Name']."<br />".$aValues['Address']."<br />".
$aValues['City']."<br />".$aValues['State']."<br />".
$aValues['Zip']."<br /><br />Phone: ".$aValues['Phone']."<br />".
"<a href=\"mailto:".$aValues['E-mail']."\">".$aValues['E-mail']."</a>";
        } else {
$sInfo = "Customer with ID $sID doesn't exist.";


    <div id="divInfoToReturn"> <?php echo $sInfo ?> </div>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <title>Customer Account Information</title>
    <script type="text/javascript">
        var url = "GetCustomerData.php?id="; // The server-side script
       function handleHttpResponse() {   
        if (http.readyState == 4) {
              if(http.status==200) {
                  var results=http.responseText;
              document.getElementById('divCustomerInfo').innerHTML = results;
        function requestCustomerInfo() {     
            var sId = document.getElementById("txtCustomerId").value;
  "GET", url + escape(sId), true);
            http.onreadystatechange = handleHttpResponse;
function getHTTPObject() {
  var xmlhttp;

    xmlhttp = new XMLHttpRequest();
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  return xmlhttp;

var http = getHTTPObject(); // We create the HTTP Object
    <p>Enter customer ID number to retrieve information:</p>
    <p>Customer ID: <input type="text" id="txtCustomerId" value="" /></p>
    <p><input type="button" value="Get Customer Info" onclick="requestCustomerInfo()" /></p>
    <div id="divCustomerInfo"></div>

-- phpMyAdmin SQL Dump
-- version 2.6.0-pl3
-- Host: localhost
-- Generation Time: Apr 30, 2006 at 05:45 PM
-- Server version: 4.1.8
-- PHP Version: 5.0.3
-- Database: `ajax_ex`

-- --------------------------------------------------------

-- Table structure for table `customers`

CREATE TABLE `customers` (
  `CustomerId` int(11) NOT NULL auto_increment,
  `Name` varchar(255) NOT NULL default '',
  `Address` varchar(255) NOT NULL default '',
  `City` varchar(255) NOT NULL default '',
  `State` varchar(255) NOT NULL default '',
  `Zip` varchar(255) NOT NULL default '',
  `Phone` varchar(255) NOT NULL default '',
  `E-mail` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`CustomerId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Sample Customer Data';

-- Dumping data for table `customers`

INSERT INTO `customers` VALUES (1, 'Suraj Thapliya', 'Naxal, Bhagbati', 'Kathmandu', 'KTM', '0977', '977-9803165329', '[email protected]');
INSERT INTO `customers` VALUES (2, 'Birijan Maharjan', 'Kathmandu', 'Kathmandu', 'Ktm', '977', '9803020016', '[email protected]');

mysql date/time converters
Categories : PHP, MySQL, Databases, Date Time
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
PHP Calendar Web App
Categories : PHP, Databases, MySQL, Date Time, Calendar
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
In Mysql, the 'datetime' data type is used to store date that looks like '2007-10-16 16:26:30'. we are going to design a function called mysqldate() that takes a mysql date and output format as input and outputs a well formated date.
Categories : PHP, Date Time, Databases, MySQL
Phorum, MySQL, Language, UK date format, MySQL UK Date format
Categories : PHP, Date Time, Strings, MySQL, Databases
AJAX Application
Categories : PHP, AJAX, Databases, MySQL
List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP
Inserting data to a MySQL Database using AJAX
Categories : AJAX, HTTP, PHP, Databases, MySQL
Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays.
Categories : Calendar, Date Time, PHP, Databases, MySQL
 Antonio Ciccarone wrote : 1764
Good job here, this actually worked without a hitch.  It's 
going to be fun to rip it apart and use it for my own 
development.  Thanks for sharing!
 Marvin Ochieng wrote : 1809
hi..thank you for your very good tutorial, it got me to do
 something i never managed before, quite pleased with 
mylself...however, i have a minor form 
queries the db and returns radio buttons according to the 
user's choice a select list above..when i submit the whole 
form, the values of the radio buttons drawn from the's a snippet from the php file that's 
called by the XMLHttpRequest.

while($row mysql_fetch_array($result))
 if (
$int%== 0)
$url "vdesign.php?desc=".$row['description']."&title=".$row['title']."";
"<input type='radio' name='design' value='".$row['title']."' /><a href = 'vdesign.php?desc=".$row['description']."&title=".$row['title']."' onclick=\"return popitup('$url')\">".$row['title']."</a><br/><br/>";

$url "vdesign.php?desc=".$row['description']."&title=".$row['title']."&type=".$row['type']."";
"<input type='radio' name='design' value='".$row['title']."' /><a href = 'vdesign.php?desc=".$row['description']."&title=".$row['title']."' onclick=\"return popitup('$url')\">".$row['title']."</a>  ";

 ninanano ninanano wrote : 1815
thanks for your codes. really appreciate it. just want to 
ask, i try to enter character such as M0001 into the text 
field and begin searching, but the script wont do it. 
where should i change to make sure character+number such 
as M00001 can be accepted? please help, really in need!!
 Muhammad Shafique wrote : 1860
Your Code Example is Good . Run very well in Firfox and IE.

But Problem is that in IE6 . this script run first time 
successfully but when any changes in table. this script not execute with changes. this run as first time load.

If any record insert this script will not get that record 
in IE. But get value in Firfox successfully.

please can you help that how this problem can solve.

with thanks
 Suraj Thapaliya wrote : 1861
Thanks all of you. 

To make it work in IE 6 put this code in your php file at top

header("Cache-Control: no-cache"); 
 Suraj Thapaliya wrote : 1862
One more thing this code is little old So you can find my AJAX code at

which gives u the easy way to do the bunch of things 
 Muhammad Shafique wrote : 1863
HI Suraj Thapaliya 
According to your sugestion i add no cache in header.
now this is working good in IE6.
 Chris Green wrote : 1867
Can you tell me how to do the same thing, but with a dropdown list that you select a name from and shows address, phone and other things below?
 Emmanuel Constant wrote :1874
How would you setup the code for Oracle database?