SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xmlhttprequest and PHP

    Hi All,

    I am trying to configure livesearch.js to work through a php page that I have created, its a dead simple php script that I have tested and I know it works, the only problem is that the liverequest doesnt seem to be posting anything through when I use the live search.

    the php code is:

    PHP Code:
    $db_cid mysql_connect('localhost','user','pass')
     or die(
    "<p><b><font color=red>Oh Crap!</font></b></p>/n<p>It seems MySQL is down. (Mysql Connection Error: " mysql_error() . ") so please try again later.</p>");
      
      function 
    db_query($sql) {
          global 
    $db_cid;
          
    $result mysql_db_query('db',$sql,$db_cid)
         or die(
    "<p><strong>Error in MySQL Query:</strong><br />$sql</p><p><strong>MysQL Says:</strong><br />" mysql_error() . "</p>" );
          return 
    $result;
      }
      
      
    $searchQuery $HTTP_RAW_POST_DATA['liveSearch'];
      
      
    $sql "SELECT * FROM PigBlogs WHERE "
            
    ."Blogage LIKE '%".$searchQuery."%' "
            
    ."LIMIT 5 ";
      
            echo 
    $sql;
      
    $result db_query($sql);
      
      if(
    mysql_num_rows($result) > 0) {
          echo(
    "<ol>");
              while(
    $row mysql_fetch_array($result)) {
              
             echo(
    "<li><a href=http://www.guinnesspig.net/?blog=".$row['BlogID'].">".$row['Bolgtitle']."</a></li>");
      
          }
          echo(
    "</ol>");
          } 
          else {
          echo(
    "<p>found nothing</p>");
      } 
    I read that its better to use $HTTP_RAW_POST_DATA which is also turned on in the php.ini on my server.

    the url of the live request that I am trying to sort out is:
    http://www.guinnesspig.net/xmlhttprequest/

    then the .js file is http://www.guinnesspig.net/xmlhttpre...liveRequest.js

    I really am stumped as to why the page is not posting through the xmlhttprequest.

    Any suggestions would be very helpfull

    Thanks in advance.
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like it! Works for me, IE6 PC.

  3. #3
    Beer Monster -Ox's Avatar
    Join Date
    Apr 2003
    Location
    sowth afreeka
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOPS!! I totally forgot to post again! its now working, it had a few teething problems!

    which after a few hours I have figured out.

    Basically the xmlhttprequest doesnt use an form tag or anything it makes it own GET or POST in this case GET that is named as 's' so instead of writing the query on my PHP page it now looks like this

    PHP Code:
      $sql "SELECT * FROM PigBlogs WHERE "
            
    ."Bolgtitle LIKE '%".$_GET['s']."%' OR "
            
    ."Blogage LIKE '%".$_GET['s']."%' "
            
    ."ORDER BY BlogID DESC "
            
    ."LIMIT 5 "
    if ya'll would like me to post the code for all the pages, let me know and I will sent it to ya via email, its REALLY simple once you know how to do it, frustrating when it doesnt work hahaa.

    Cheers
    My postings are a natural product.
    The slight variations in spelling and grammar enhance its
    individual character and beauty and in no way are to be
    considered flaws or defects - http://www.guinnesspig.net

  4. #4
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you happen to know if its possible to call a js timer through php, with http request? Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •