www.webdeveloper.com
Results 1 to 2 of 2

Thread: A Simple Search Form Not Working

  1. #1
    Join Date
    May 2003
    Location
    Australia
    Posts
    368

    A Simple Search Form Not Working

    I've set up a simple search form but on POST it get's no result, I've tested it with data I know is definitely in the database, not sure what I am doing wrong...

    Search Form
    Code:
    <html>
        <head>
            <title>Search Test</title>
        </head>
        <body topmargin="0" leftmargin="0">
            <form action="searchResults.php" method="post">
                Search Term <input type="text" name="searchterm"><br />
                <input type="submit" value="Search">
            </form>
        </body>
    </html>
    PHP
    PHP Code:
    <?php
    include 'library/config.php';
    include 
    'library/opendb.php';

    /*set varibles from form */
    $searchterm $_POST['searchterm'];
    trim ($searchterm);
    /*check if search term was entered*/
    if (!$searchterm){
        echo 
    'Please enter a search term.';
    }
    /*add slashes to search term*/
    if (!get_magic_quotes_gpc())
    {
    $searchterm addslashes($searchterm);
    }

    /*query the database*/
    $query "SELECT * FROM `tblmembers` WHERE `FirstName` LIKE '%".$searchterm."%' AND `MemberApproved`='A'";
    $result mysql_query($query) or die('Error, query failed'.mysql_error());

    /*number of rows found*/
    $num_results $result->num_rows;

    echo 
    '<p>Found: '.$num_results.'</p>';
    /*loops through results*/
    for ($i=0$i <$num_results$i++)
    {
    $num_found $i 1;
    $row $result->fetch_assoc();
    echo 
    "$num_found. ".($row['FirstName'])." <br />";
    }

    include 
    'library/closedb.php';
    ?>
    Last edited by tomyknoker; 04-15-2007 at 10:03 AM.

  2. #2
    Join Date
    Mar 2007
    Posts
    11
    I can't see any obvious problems, but isn't shouldn't $result->num_rows; be $num_results = $result->num_rows(); as it's a function?

    Sorry i can't be any more help ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles