What is being sent to server?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tessie  Sweden

    What is being sent to server?

    Hi all!

    I have fought with this query and php-script for days now. All that is
    sent to the server from the input form is the number "1" or the symbol
    "%". None of the actual "RECIPE_NAM ES" that I have searched for, has
    generated any results.

    Please help! This is my error message after echoing my query and some
    helping testlines to the screen:

    "1test SELECT * FROM DESCRIPTION WHERE RECIPE_NAME LIKE '%1%' gar in i
    whileslinganWar ning: mysql_fetch_obj ect(): supplied argument is not a
    valid MySQL result resource in
    /afs/nada.kth.se/home/t/u1j80hrt/public_html/2D1517/XMLprojekt/search.php
    on line 30"

    And these are parts of my two files: start.php and search.php:

    *************** *************** *************** *************** *****
    <head><title>Sö k i kokboken</title>
    </head>
    <h1>Sök i kokboken</h1>
    <form method="GET" action="search. php">
    <table width="90%" align="center">
    <tr><td>Sök efter:</td><td><input type="text" name="search" value=""
    size='30' maxlength='255' ></td></tr>
    <td></td><td><input type="submit" name="submit" value="Sök"></td></tr>
    </table>
    </form>
    <?php
    $dbH = mysql_connect(" pub.gt.kth.se", "lisaalf", "lisaalf") or die
    ('Could not connect to MySQL server');
    mysql_select_db ("lisaalf") or die("Could not select database");
    ?>
    </body>
    *************** *************** *************** *****

    -----------------------------------------------------
    <?php

    $searchstring = isset($_GET['search']); //Hämtar söksträngen
    echo $searchstring;
    if ($searchstring) //Om en söksträng har skrivits in..

    {
    echo "test";
    $dbH = mysql_connect(" pub.gt.kth.se", "lisaalf", "lisaalf") or die
    ('Could not connect to MySQL server');
    mysql_select_db ("lisaalf") or die("Could not select database");
    $returnstring ="";
    $query1 = "SELECT * FROM DESCRIPTION WHERE RECIPE_NAME LIKE
    '%$searchstring %'";
    echo "<pre>\n$query1 \n</pre>";


    if ($query1)
    {
    echo "gar in i whileslingan";

    while ($line = mysql_fetch_obj ect($query1)) {
    --------------------------------------------------------------------
  • Gordon Burditt

    #2
    Re: What is being sent to server?

    >I have fought with this query and php-script for days now. All that is[color=blue]
    >sent to the server from the input form is the number "1" or the symbol
    >"%". None of the actual "RECIPE_NAM ES" that I have searched for, has
    >generated any results.[/color]

    Where did you call mysql_query(), to actually DO a query? You feed
    mysql_fetch_obj ect() the result handle that is returned from
    mysql_query().

    Gordon L. Burditt

    Comment

    • Daedalus

      #3
      Re: What is being sent to server?


      "Tessie Sweden" <tessan@tessan. se> wrote in message
      news:f4244480.0 412051254.200c3 842@posting.goo gle.com...[color=blue]
      > Hi all!
      >
      > I have fought with this query and php-script for days now. All that is
      > sent to the server from the input form is the number "1" or the symbol
      > "%". None of the actual "RECIPE_NAM ES" that I have searched for, has
      > generated any results.
      >
      > Please help! This is my error message after echoing my query and some
      > helping testlines to the screen:
      >
      > "1test SELECT * FROM DESCRIPTION WHERE RECIPE_NAME LIKE '%1%' gar in i
      > whileslinganWar ning: mysql_fetch_obj ect(): supplied argument is not a
      > valid MySQL result resource in
      > /afs/nada.kth.se/home/t/u1j80hrt/public_html/2D1517/XMLprojekt/search.php
      > on line 30"
      >
      > And these are parts of my two files: start.php and search.php:
      >
      > *************** *************** *************** *************** *****
      > <head><title>Sö k i kokboken</title>
      > </head>
      > <h1>Sök i kokboken</h1>
      > <form method="GET" action="search. php">
      > <table width="90%" align="center">
      > <tr><td>Sök efter:</td><td><input type="text" name="search" value=""
      > size='30' maxlength='255' ></td></tr>
      > <td></td><td><input type="submit" name="submit" value="Sök"></td></tr>
      > </table>
      > </form>
      > <?php
      > $dbH = mysql_connect(" pub.gt.kth.se", "lisaalf", "lisaalf") or die
      > ('Could not connect to MySQL server');
      > mysql_select_db ("lisaalf") or die("Could not select database");
      > ?>
      > </body>
      > *************** *************** *************** *****
      >
      > -----------------------------------------------------
      > <?php
      >
      > $searchstring = isset($_GET['search']); //Hämtar söksträngen
      > echo $searchstring;
      > if ($searchstring) //Om en söksträng har skrivits in..
      >
      > {
      > echo "test";
      > $dbH = mysql_connect(" pub.gt.kth.se", "lisaalf", "lisaalf") or die
      > ('Could not connect to MySQL server');
      > mysql_select_db ("lisaalf") or die("Could not select database");
      > $returnstring ="";
      > $query1 = "SELECT * FROM DESCRIPTION WHERE RECIPE_NAME LIKE
      > '%$searchstring %'";
      > echo "<pre>\n$query1 \n</pre>";
      >
      >
      > if ($query1)
      > {
      > echo "gar in i whileslingan";
      >
      > while ($line = mysql_fetch_obj ect($query1)) {
      > --------------------------------------------------------------------[/color]


      Comment

      • Daedalus

        #4
        Re: What is being sent to server?

        Sorry for the previous post, my finger slipped.

        There's a couple of major errors in your script:
        [color=blue]
        > -----------------------------------------------------
        > <?php
        >
        > $searchstring = isset($_GET['search']); //Hämtar söksträngen[/color]

        // FIRST ERROR:

        /* You assign to $searchstring the return value of isset(..) wich return a
        bool value (1 for true, 0 for false). So if $_GET['search'] is set, 1 is
        assigned to $searchstring, if it is not set, 0 is assigned to $searchstring.
        */

        // POSSIBLE CORRECTION:
        if(isset($_GET['search'])){
        $searchstring = $_GET['search'];
        }
        [color=blue]
        > echo $searchstring;
        > if ($searchstring) //Om en söksträng har skrivits in..
        >
        > {
        > echo "test";
        > $dbH = mysql_connect(" pub.gt.kth.se", "lisaalf", "lisaalf") or die
        > ('Could not connect to MySQL server');
        > mysql_select_db ("lisaalf") or die("Could not select database");
        > $returnstring ="";
        > $query1 = "SELECT * FROM DESCRIPTION WHERE RECIPE_NAME LIKE
        > '%$searchstring %'";
        > echo "<pre>\n$query1 \n</pre>";
        >[/color]


        // SECOND ERROR:

        // As stated by Gordon, now you need to actually query the database
        ..
        // SOLUTION:
        $result1 = mysql_query($qu ery1) or die("MySQL error: ".mysql_error() );
        [color=blue]
        >[/color]

        // And here you need to test and fetch the result from the mysql_query()
        instead of the query string:
        if ($result1)
        {[color=blue]
        > echo "gar in i whileslingan";[/color]

        while ($line = mysql_fetch_obj ect($result1)) {[color=blue]
        > --------------------------------------------------------------------[/color]


        Comment

        Working...