query not returning

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Morgan

    query not returning

    Can anyone tell me whats wrong with this code? The variables are being past
    from other page and the $connection is ok as is $result. this query should
    return 6 rows.
    the error message I get is "Warning: mysql_fetch_row (): supplied argument is
    not a valid MySQL result resource in /var/www/html"

    The user selects a field from a drop down then enters the parameter to
    search the field with in a input type text field then clicks a button to run
    the query. I'm new at this so any help appreciated.

    Bob

    <?php
    $SField=($_POST["SField"]);
    $Parameter = ($_POST["Parameter"]);
    $connection = mysql_connect(" localhost", "connection ", "pword");
    print_r($Parame ter);
    print_r(connect ion);
    mysql_select_db ("HelpData", $connection);
    $FLDquery= "select * from tblWorkstation where '".$SField." ' =
    ".$Parameter."" ;
    $result = mysql_query($FL Dquery, $connection) ;


    while ($row = mysql_fetch_row ($result))
    {

    for($i=0;$i<mys ql_numFields($r esult);$i++)
    echo $row[$i]." ";
    echo "\n";
    }



    ?>


  • Jochen Daum

    #2
    Re: query not returning

    Hi Robert!

    Robert Morgan wrote:
    [color=blue]
    > Can anyone tell me whats wrong with this code? The variables are being
    > past from other page and the $connection is ok as is $result.[/color]

    Use print_r($result );

    I doubt it is ok -- should return "resource(. .."
    [color=blue]
    > this query
    > should return 6 rows.
    > the error message I get is "Warning: mysql_fetch_row (): supplied argument
    > is not a valid MySQL result resource in /var/www/html"[/color]

    Alternatively, paste the query into phpmyadmin.[color=blue]
    >
    > The user selects a field from a drop down then enters the parameter to
    > search the field with in a input type text field then clicks a button to
    > run the query. I'm new at this so any help appreciated.
    >
    > Bob
    >
    > <?php
    > $SField=($_POST["SField"]);
    > $Parameter = ($_POST["Parameter"]);
    > $connection = mysql_connect(" localhost", "connection ", "pword");
    > print_r($Parame ter);
    > print_r(connect ion);[/color]

    where is the $ in $connection. Also, use error_reporting (E_ALL);

    HTH, Jochen
    --
    PHPDBEditTk: Toolkit for nice and easy
    administration interfaces. http://phpdbedittk.sourceforge.net

    Comment

    • Rainer Herbst

      #3
      Re: query not returning

      Robert Morgan schrieb:[color=blue]
      > Can anyone tell me whats wrong with this code? The variables are being past
      > from other page and the $connection is ok as is $result. this query should
      > return 6 rows.
      > the error message I get is "Warning: mysql_fetch_row (): supplied argument is
      > not a valid MySQL result resource in /var/www/html"
      >
      > The user selects a field from a drop down then enters the parameter to
      > search the field with in a input type text field then clicks a button to run
      > the query. I'm new at this so any help appreciated.
      >
      > Bob
      >
      > <?php
      > $SField=($_POST["SField"]);
      > $Parameter = ($_POST["Parameter"]);
      > $connection = mysql_connect(" localhost", "connection ", "pword");
      > print_r($Parame ter);
      > print_r(connect ion);
      > mysql_select_db ("HelpData", $connection);
      > $FLDquery= "select * from tblWorkstation where '".$SField." ' =
      > ".$Parameter."" ;
      > $result = mysql_query($FL Dquery, $connection) ;
      >
      >
      > while ($row = mysql_fetch_row ($result))
      > {
      >
      > for($i=0;$i<mys ql_numFields($r esult);$i++)
      > echo $row[$i]." ";
      > echo "\n";
      > }
      >
      >
      >
      > ?>
      >
      >[/color]

      Your query will result in an SQL statement like:
      select * from tblWorkstation where 'myField' = xyz;

      but the statement should look like
      select * from tblWorkstation where myField = 'xyz';

      The quota converts the fieldname into a string, which will normally not
      be equal to the parameter!

      HTH!
      Rainer

      --
      ------------------------------------------------
      Rainer Herbst Linux - Registered
      ZEIK User #319157
      Universität Potsdam Usual disclaimers applies!
      ------------------------------------------------

      Comment

      Working...