Results 1 to 7 of 7

Thread: This code is giving me some trouble

  1. #1
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default This code is giving me some trouble

    Hello,
    This code keeps tripping the error notifier. I've validated it. The $url is valid as I see the output xml if I go to the "real address." Any thoughts on this would be appreciated.


    Code:
     <?php
    if (!isset($_GET['qry'])) {
     
    	echo '<ul class="listings-results search">';
      echo "<li><h4>We’re sorry, search is currently undergoing maintenance.</h4></li></ul>";
    }
    								
    $qry = urlencode($_GET['qry']);
    $url = "http://myserver.com/SearchServlet?cname=newyork&fe=utf-8&st=adv&q_phr=&q_low=&q_not=&oc=all&pagesize=100&q_all={$qry}";
    
    $ch = curl_init($url);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $xml_string = curl_exec($ch);
    
    curl_close($ch);
    
    $xml = new SimpleXMLElement($xml_string);
     
    echo  '<pre>';
    
    //echo var_dump($xml->results); exit;
    
    if ($xml->results>0){
    echo '<ul class="listings-results search">';
    }
    foreach($xml->results->result as $the) {
    	 
       echo '<li class="listing-results">'.'<a href="'.$the->url.'">'.'<h4>'.fix_curlys($the->title).'</h4>';
       echo '<span class="desc">'.fix_curlys($the->description).'</span>'.'</a>'.'</ul>';
    
    }  
    
    echo '</pre>'; 
    
    
    function fix_curlys($text){
    
    return str_replace(
     array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
     array("'", "'", '"', '"', '-', '--', '...'),
     $text);
    // Next, replace their Windows-1252 equivalents.
     $text = str_replace(
     array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
     array("'", "'", '"', '"', '-', '--', '...'),
     $text);
     
    }
    ?>
    Here is the input from the search form

    Code:
    <form action="/results2.php" accept-charset="UTF-8" method="post" id="search-form">
    <input type="text" id="search-field" maxlength="128" value="Search!" title="Enter the terms you wish to search for." onfocus="if (this.value==this.defaultValue) this.value='';" onblur="if (this.value=='') this.value=this.defaultValue;" name="qry" class="form-text"/>ev
    <button class="form-submit"/>
    </form>
    Thanks in Advance.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    What validator? What 'error notifier'? What's error is being given?

    At a glance, the <li class="listing-results"> tag doesn't appear to be closed - there's a closing </ul> but no closing </li>.

    If you require further help, please provide more information - clearly state the problem and desired outcome - and provide a link to your page.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Validated here: http://www.meandeviation.com/tutoria...ntax-check.php

    It trips the under maintenance (i guess error isnt the best term to use) code.
    Code:
    if (!isset($_GET['qry'])) {
     
    	echo '<ul class="listings-results search">';
      echo "<li><h4>We’re sorry, search is currently undergoing maintenance.</h4></li></ul>";
    }
    Which I am assuming is because the $qry is not being set by the form.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Your form uses method="post" but the php in using $_GET

    Since you're form is not changing anything on the server, change it to method="get"

    method="post" with $_POST

    method ="get" with $_GET

    More info on that : http://php.net/manual/en/tutorial.forms.php
    Last edited by Beverleyh; 01-12-2013 at 08:25 AM.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Hi Beverleyh,

    Thanks for taking the time to try and help me. I have swapped the method to
    Code:
    method="get"
    on the search form but it still does not seem to be populating the
    Code:
    $qry
    variable.

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    It appears to be working OK at this side.

    I removed reference to the SimpleXMLElement class and foreach loop to get my test page to to work (obviously, without the SimpleXMLElement class and variables for the foreach loop, my page was throwing up errors) , but it's otherwise getting the search term and setting the variable fine - I just echo'd out the variables on the page so you can see: http://fofwebdesign.co.uk/template/_...h-get/test.php

    One thing I noticed is that you haven't specified the type attribute for your button (or closed the button tag). That can cause browsers to submit different values so depending on the browsers you're testing in, that may have been the problem. On my test page I set the button type to submit like this;
    Code:
    <button type="submit">SEARCH</button>
    Last edited by Beverleyh; 01-12-2013 at 04:09 PM.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  7. The Following User Says Thank You to Beverleyh For This Useful Post:

    itivae (01-12-2013)

  8. #7
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Thanks so much. It turned out that the CMS had reverted the original searchforms code to point to another page :-/ Thank you again for taking a look.

Similar Threads

  1. Help! almost giving up..
    By Mystech in forum CSS
    Replies: 3
    Last Post: 09-10-2008, 08:47 AM
  2. Replies: 3
    Last Post: 05-22-2008, 04:32 PM
  3. Having trouble with java window open code
    By Otto in forum JavaScript
    Replies: 4
    Last Post: 01-28-2008, 11:06 PM
  4. Giving Two names to one DIV
    By tp4f in forum Looking for such a script or service
    Replies: 1
    Last Post: 09-10-2007, 11:20 AM
  5. Replies: 1
    Last Post: 02-22-2007, 09:25 PM

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
  •