Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Search.php

  1. #1
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts

    Internet Explorer Search.php

    I have this snip of code I got from a tutorial, I've tested it on safari and it works fine but when I go onto my windows computer and try it on ie7 It just goes to the search page with no results. As if I didn't search for anything.

    Code:

    PHP Code:
    <?php
    if(isset($_POST['submit'])){
    $problem FALSE;
     
    if(empty(
    $_POST['search'])){
    $problem TRUE;
    echo 
    "<p style=\"color:#FF0000;\">Please enter a search term!</p>";
    }
    if(!
    $problem){
    $text escape_data($_POST['search']);
    $query "SELECT * from anime_reviews WHERE title LIKE '%$text%' OR summary LIKE '%$text%' OR genres LIKE '%$text%'";
    $result = @mysql_query($query);
    $query2 "SELECT id, title, summary, DATE_FORMAT(date, '%M %d, %Y') as sd FROM anime_reviews ORDER BY id DESC limit 15";
    $result2 = @mysql_query($query);
    if(
    $result && $result2){
    echo 
    "<h1>found " mysql_num_rows($result) . " results</h1><br />";
    echo 
    "<ul>";
    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)){
    $view 'anime.php?id=' $row['id'];
     
    echo 
    '<li>' $row['id'] . '&nbsp;-&nbsp;<a href="' $view '">' $row['title'] . '</a></li>';
    }
    echo 
    "</ul><br />
    <a href=\"search.php\">Search Again?</a>"
    ;
    }
    else
    {
    echo 
    "No posts matched your query";
    }
    }
    }
    else
    {
    ?>
    <form id="search" action="search.php?search" method="post">
    Keyword: <input type="text" name="search" size="30" class="text" /><br />
    <input type="submit" name="submit" value="Search" />
    </form>
    <?php
    }
    ?>
    Last edited by Dat; 03-06-2008 at 05:47 AM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try this
    PHP Code:
    <?php
    // just in case register globals is on, someone can't pass true or false through the url making $problem to be whatever they enter
    $problem '';
    if(isset(
    $_POST['submit']) && $_POST['submit'] == 'Search')
    {
        
    // just in case register globals is on, someone can't pass true or false through the url making $problem to be whatever they enter
        
    if(isset($_GET['problem']))
        {
            
    $_GET['problem'] = FALSE;
        }
        
    $problem FALSE;     
        if(
    $_POST['search'] == '')
        {
            if(isset(
    $_GET['problem']))
            {
                
    $_GET['problem'] = TRUE;
            }
            
    $problem TRUE;
            echo 
    "<p style=\"color:#FF0000;\">Please enter a search term!</p>";
        }
        if(!
    $problem)
        {
            
    $text escape_data($_POST['search']);
            
    $query "SELECT * from anime_reviews WHERE title LIKE '%$text%' OR summary LIKE '%$text%' OR genres LIKE '%$text%'";
            
    // You need some error checking on your queries. If you are getting errors then find out why you are getting them rather than supressing them
            
    $result mysql_query($query) or die(mysql_error());
            
    $query2 "SELECT id, title, summary, DATE_FORMAT(date, '%M %d, %Y') as sd FROM anime_reviews ORDER BY id DESC limit 15";
            
    $result2 mysql_query($query) or die(mysql_error());
            
            
    // I would check for mysql_num_rows instead.
            
    if(mysql_num_rows($result) > && mysql_num_rows($result2) > 0)
            {
                echo 
    "<h1>found " mysql_num_rows($result) . " results</h1><br />";
                echo 
    "<ul>";
                while (
    $row mysql_fetch_array($resultMYSQL_ASSOC))
                {
                    
    $view 'anime.php?id=' $row['id']; 
                    echo 
    '<li>' $row['id'] . '&nbsp;-&nbsp;<a href="' $view '">' $row['title'] . '</a></li>';
                }
                echo 
    "</ul><br />
                <a href=\"search.php\">Search Again?</a>"
    ;
            }    
            else
            {
                echo 
    "No posts matched your query";
            }
        }
    }
    else
    {
    ?>
    <!--IE was having issues with the form having id="search" and the input having name="search". IE treats ids and names as the same thing so it was confused -->
    <form action="search.php" method="post">
    Keyword: <input type="text" name="search" size="30" class="text" /><br />
    <input type="submit" name="submit" value="Search" />
    </form>
    <?php
    }
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    I've updated it with your provided coded. Still doesn't work in Ie. Works fine with safari still.
    Here is were my search page is: http://www.romanceanime.com/search.php

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I just did a search for the word "test" and I got results. Make sure you aren't seeing a cached version. Hit CTRL + F5. Your BETA search also has a form with id="search", you need to remove that.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Okay, it works ONLY if I press on the search key, I've been pressing enter and it doesn't work. How do I fix that?

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You didn't fix the code at all. Your BETA search has id="search" in it. Remove that please.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Alright I've updated it, still doesn't work.

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Hmm looks like this has always been an issue in IE.

    http://muffinresearch.co.uk/archives...ubmit-buttons/
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    So what should I do? Make two input fields?

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I wonder if a hidden one will suffice. Something like
    Code:
    <input type="hidden" name="dummy">
    or
    Code:
    <input type="text" name="dummy" style="display:none;">
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    I've researched about this issue on google and found that there is a PHP solution but have not found the proper source to fix my problem. If there are any PHP solution please reply. ~ Thank you

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where did you read that there was a solution? You can probably give the form its own name and check for submission of that though I think thats we were doing already don't know.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    It's much better to use: GET rather than POST

  • #14
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Alright I got my search to work on ie now, and I got it work with multiple keywords but it displays double results. Example I search "and and" Stupid example but you get my point.

    I think I should use preg_replace() but I don't know how to confront this with my code, I won't want to screw up anything with my nooby fingers.

    If you see anything NOOBY in this code please tell me I'm learning, like the way I organize or.. whatever!

    PHP Code:
                                    <form method="get" action="search3.php">
                                        <input type="text" name="search" size="30" />
                                        <input type="submit" value="Search" />
                                    </form>
                                    <?php
    include("include/db_connect.inc.php");

    function 
    escape_data ($data) {
        global 
    $dbc// Need the connection
        
    if (ini_get('magic_quotes_gpc')) {
            
    $data stripslashes($data);
        }
        return 
    mysql_real_escape_string(trim($data), $dbc);
    }

    if(isset(
    $_GET['search'])){
        
    $search trim(escape_data($_GET['search'])); // Escape and trim withspaces
        
    $search_array explode(' ',$search); // Seperate each keyword
        
        
    if ($search == '') { // If no keyword is entered
            
    $resultmsg =  'Search Error: Please enter a search...' ;
        }
        if (!isset(
    $resultmsg)) {
            foreach (
    $search_array as $keyword){
                
    $query "SELECT * FROM anime_reviews WHERE title LIKE '%$keyword%' OR genres LIKE '%$keyword%' OR summary LIKE '%$keyword%' ORDER BY title  ASC" 
                
    $result mysql_query ($query);

                
    // Check number of rows and if more than 0 continue
                
    if(mysql_num_rows($result) > 0){
                    while(
    $data mysql_fetch_array($result)){
                    
    $data['summary'] = substr($data['summary'], 0300);
                        echo 
    '<a href="/anime.php?id=' $data['id'] . '">' $data['title'] . '</a> (' $data['title_jap'] . ')<br>' $data['summary'] . '...<br>';
                    }
                } else {
                
    $resultmsg 'No entries match your search';
                }
            }
        }
    }
    echo @
    $resultmsg;
    ?>

  • #15
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dat View Post
    Alright I got my search to work on ie now, and I got it work with multiple keywords but it displays double results. Example I search "and and" Stupid example but you get my point.

    I think I should use preg_replace() but I don't know how to confront this with my code, I won't want to screw up anything with my nooby fingers.

    If you see anything NOOBY in this code please tell me I'm learning, like the way I organize or.. whatever!

    PHP Code:
                                    <form method="get" action="search3.php">
                                        <input type="text" name="search" size="30" />
                                        <input type="submit" value="Search" />
                                    </form>
                                    <?php
    include("include/db_connect.inc.php");

    function 
    escape_data ($data) {
        global 
    $dbc// Need the connection
        
    if (ini_get('magic_quotes_gpc')) {
            
    $data stripslashes($data);
        }
        return 
    mysql_real_escape_string(trim($data), $dbc);
    }

    if(isset(
    $_GET['search'])){
        
    $search trim(escape_data($_GET['search'])); // Escape and trim withspaces
        
    $search_array explode(' ',$search); // Seperate each keyword
        
        
    if ($search == '') { // If no keyword is entered
            
    $resultmsg =  'Search Error: Please enter a search...' ;
        }
        if (!isset(
    $resultmsg)) {
            foreach (
    $search_array as $keyword){
                
    $query "SELECT * FROM anime_reviews WHERE title LIKE '%$keyword%' OR genres LIKE '%$keyword%' OR summary LIKE '%$keyword%' ORDER BY title  ASC" 
                
    $result mysql_query ($query);

                
    // Check number of rows and if more than 0 continue
                
    if(mysql_num_rows($result) > 0){
                    while(
    $data mysql_fetch_array($result)){
                    
    $data['summary'] = substr($data['summary'], 0300);
                        echo 
    '<a href="/anime.php?id=' $data['id'] . '">' $data['title'] . '</a> (' $data['title_jap'] . ')<br>' $data['summary'] . '...<br>';
                    }
                } else {
                
    $resultmsg 'No entries match your search';
                }
            }
        }
    }
    echo @
    $resultmsg;
    ?>
    Really what is the best solution go about this?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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