WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

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.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Data Retrieve from Mysql using AJAX with PHP
Categories : PHP, AJAX, Date Time, Databases, MySQL Click here to Update Your Picture
Suraj Thapaliya
Date : May 01st 2006
Grade : 3 of 5 (graded 27 times)
Viewed : 59435
File : 4389.zip
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

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

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:1.8.0.2)
Gecko/20060308 Firefox/1.5.0.2
Browse Name:         Microsoft Internet Explorer / 6.0
Browse Name :        Mozilla 1.5


GetCustomerData.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Get Customer Data</title>
<?php
   
   
//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";
       
    if(
$sInfo == '') {
        if(
$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.";
        }
    }
   
   
mysql_close($oLink);

?>
   
   

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



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

<html>
<head>
    <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;
            http.open("GET", url + escape(sId), true);
            http.onreadystatechange = handleHttpResponse;
            http.send(null);
        }
function getHTTPObject() {
  var xmlhttp;

  if(window.XMLHttpRequest){
    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
</script>
</head>
<body>
    <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>
</body>
</html>



customers.txt
-- 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', 'surajthapaliya@gmail.com');
INSERT INTO `customers` VALUES (2, 'Birijan Maharjan', 'Kathmandu', 'Kathmandu', 'Ktm', '977', '9803020016', 'birijan@wlink.com.np');



Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time
mysql date/time converters
Categories : PHP, MySQL, Databases, Date Time
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
Phorum, MySQL, Language, UK date format, MySQL UK Date format
Categories : PHP, Date Time, Strings, MySQL, Databases
List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP
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
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
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
How to Insert a Date Format Into MySQL from PHP
Categories : PHP, Databases, MySQL, Date Time, Beginner Guides
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
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
How to Convert a MySQL Timestamp to a USA Date & Time
Categories : PHP, MySQL, Databases, Date Time
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
formating MySQL Timestamp to get a propper Output. related : Timestamp, ereg_replace, mysql, substr
Categories : MySQL, PHP, Date Time, Databases
 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!