Jump to content

Retrieving data from a database


Death_Magnetic

Recommended Posts

Ok,i'm trying to retrieve some information from a database with AJAX/PHP.But the returned data(responseText) from the server is just the source code of the PHP file.I'm not getting just the results of echo-es.Why?I'm using WampServer and maybe it's something with the PHP,i mean it's not properly installed or something.Actually when i go to the 'www' directory of the server and open only the PHP file in the browser directly from there the result is the same,the page contains the source code of the file.So,the address in the address bar of the browser is "file:///C:/wamp/www/products.php".But when i open the same file by typing "http://localhost/products.php" in the address bar everything is ok.I'm confused,i'm very new to web programming so please tell me what's wrong.Here is the javascript and php code i'm using:

 

<script>
function http(){
    try
      {
         xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      try
      {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
     }
    }
  return xmlHttp;
}

   var xmlHttp = http();

   function getInformation()
   {
    xmlHttp.onreadystatechange = changeContent;
    xmlHttp.open("GET","HTML_editor.HTML",true);
    xmlHttp.Send(null);
   }
  
function changeContent(){
  if (xmlHttp.readyState==4){
    document.getElementById("d").innerHTML=xmlHttp.responseText;
  }
}
getInformation();
</script>

 

<?php

  $connection = mysql_connect('localhost','root','');
  if(!mysql_select_db('products'))
  {
   exit(mysql_error());
  }
  $result = mysql_query('SELECT * FROM boots',$connection) or die(mysql_error());

  while($products = mysql_fetch_array($result))
  {
   echo $products['size'];
   echo $products['price'];
  }
  mysql_close($connection);
?>

Link to comment
https://forums.phpfreaks.com/topic/117477-retrieving-data-from-a-database/
Share on other sites

<letter>:\<path> is a protocol (sorta... more like a format, but for simplicity, I'll call it a protocol) that Windows uses to access the filesystem (simplifying again... a lot).

 

 

http:// is an entirely different protocol prefix (type thingy) that is handled by a web browser, not Windows Explorer (or shell or what ever).

 

Blerh, just look up the wikipedia thingy on the HTTP protocol.  If you can't figure it out after some googling, then I'll help ;p.  Feeling lazy right now x.x.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.