Web Analytics Made Easy -
StatCounter search script not working - CodingForum

Announcement

Collapse
No announcement yet.

search script not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • search script not working

    My search script is in two parts.

    The first part is an html form page which sends the input from the form to a PHP page which

    then searches the database and returns matching results.

    But the php page doesn't work.

    Here is the source code for the HTML page:

    <html>
    <head>
    <title>searchform</title>
    </head>

    <body>
    <form action="resultbyname.php" method="POST">
    <input name=country type=text>
    <input type=submit value="search">

    </form>
    </body>
    </html>

    Here is the source code for the php page called resultbyname.php:

    <html>
    <head>
    <title>search</title>
    </head>
    <body>
    <h2>search</h2>
    <br>
    <?
    $db = mysql_connect("localhost");
    mysql_select_db("shoreconnect", $db);

    $query = "SELECT sctable.country, sctable.price FROM sctable WHERE country LIKE

    $_POST['country']";

    $result = mysql_query($query);
    while ($record = mysql_fetch_assoc($result)) {
    while (list($fieldname, $fieldvalue) = each ($record)) {
    echo $fieldname.":<b>".$fieldvalue."</b><br>";
    }
    echo"<br>";
    }
    ?>
    <br>
    </body>
    </html>

    The error message that appears is:

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or

    T_VARIABLE or T_NUM_STRING in c:\inetpub\wwwroot\resultbyname.php on line 11

    I have seperated line 11 so you can find it easily. When I changed the end of line 11 to

    ('country')"; instead of ['country']"; I get the following error message:

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\resultbyname.php on line 13

    Please help, I am baffled.

    Best Wishes
    Kjell

  • #2
    Put $_POST['country']"; onto the same line as the query.

    Comment


    • #3
      I am no expert but try this.... you need to basically concatonate the query string...



      $query = "SELECT sctable.country, sctable.price FROM sctable WHERE country LIKE '%" .$_POST['country']. "%' ";


      the % make it so that it truely searches for the phrase ...aka if there are spaces on either side etc.. or otehr letters or words... so if you were searching for "crap" it would be found in a word like "holycraptastic"...

      Comment

      Working...
      X