Jump to content

Return DB search to table


griffiths1983

Recommended Posts

Hello. I am one of the millions of noobs out there. I have a script designed to look up database and return search results to a table. The page however is blank so nothing is being output at all. Even the source is empty when I look at it.

 

So the script starts with a simple index page to enter the search term and then submit. The search.php page then has the following parsed into the browser url = search.php?query=death&submit=Search

 

I have tried searching google for all sorts of reasons for blank pages but none appear to help as they all appear to be unrelated.

 

the script i am using on the search page is below, I want to learn so some pointers would be useful please.

<?php
    mysql_connect("localhost", "user", "password") 
    mysql_select_db("db") or die(mysql_error());

    $query = $_GET['query'];
    $min_length = 1;
     if(strlen($query) >= $min_length)
     {
        $query = htmlspecialchars($query);
        $query = mysql_real_escape_string($query); 
      echo "<table border='0' width='300' align='center'>";
                echo "<tr align='center' bgcolor='#002C40' >
                <td height='35px' width='150px'>Title</td> 
                <td>Author</td></tr>";    
   $raw_results = mysql_query("SELECT * FROM avathar15 WHERE 
(`user` LIKE '%".$query."%') OR (`alliance` LIKE '%".$query."%')");
        if(mysql_num_rows($raw_results) > 0)
        {
            while($results = mysql_fetch_array($raw_results))
            {
             echo "<tr align='center' bgcolor='#0f7ea3'>
             <td height='25px'>".$results['title']."</td>
            <td>".$results['text']."</td></tr>" ;
            }
         
        }
        else{
            echo "<tr align='center' bgcolor='#6C0000'>
           <td colspan='2' height='25px'>No results</td>
            <tr>";   
             echo "</table>"; 
        }  
    }
    else{
        echo "Minimum length is ".$min_length;
    }
?>
Link to comment
https://forums.phpfreaks.com/topic/281817-return-db-search-to-table/
Share on other sites

You need to turn on error_reporting so you can see why it's doing this.  First thing I see is you are missing a ; at the end of the mysql_connect line.

 

Thank you....even for a noob that was a bad miss on my part. The script is now executing

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.