Getting data back from database

Discussion in 'PHP' started by gregd1, Apr 30, 2012.

  1. #1
    Hello,
    I am a newbe at php.
    I am building a form that needs to go back to the database and get a value when a user fills
    in a slef.


    Here is what I have so far


    
    
    <?
    $today=date('m/d/Y');
    ?>
    <html>
     <head>
      <title>Test</title>
      <script language="javascript" src="pofunctions.js"></script>
      <link rel="stylesheet" type="text/css" href="standard.css">
    <script language='javascript'>
    <!--
    
    
    function lookupStoreAddress(formname)
    {
    if (str=="")
      {
      document.getElementById("test").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("test").innerHTML=xmlhttp.responseText;
        }
      }
    
    xmlhttp.open("GET","getStoreAddress.php?store="+str,true);
    xmlhttp.send();
    
    }
    
      
    -->
    </script>
    
    </head>
    <body
    
    
    <input class='inputField' type='text' name='store' onblur="lookupStoreAddress(this)">
    <input class='inputField' type='text' name='addressStreet' readonly="readonly"  size='40'  >
    <input class='inputField' type='text' name='city' readonly="readonly"  size='40'  >
    <input class='inputField' type='text' name='state' readonly="readonly"  size='40'  >
    
    
    </body>
    </html> 
    
    
    PHP:

    I have built a php file, getStoreAddress.php

    Based on w3schools
    http://www.w3schools.com/php/php_ajax_database.asp

    Which takes in:

    
    <?php
    $store=$_GET["store"];
    ...
    
    
    ...
    
    mysql_close($con);
    ?> 
    
    PHP:

    What is the easest/best way to return the values (address, city, state) from getStoreAddress.php
    and get them on the main form.

    also,
    I am not sure what to do with the "test" in lookupStoreAddress


    thanks
     
    gregd1, Apr 30, 2012 IP
  2. infotripro

    infotripro Member

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    43
    #2
    use $_SESSION variables
     
    infotripro, May 3, 2012 IP
  3. Spudster

    Spudster Peon

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    also you forgot the add
    session_start(); up the top of your page.
     
    Spudster, May 7, 2012 IP
  4. Microsuck

    Microsuck Greenhorn

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    8
    #4
    You only need that assuming he will use the SESSION global.
     
    Microsuck, May 7, 2012 IP