Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    I am getting the following error messages in my search:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 113

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 127

    My code is below. Any help would be much appreciated.

    ****************************************************************

    <?
    //This is only displayed if they have submitted the form
    if ($searching =="yes")
    {
    echo "<h2>Results</h2><p>";

    //If they did not enter a search term we give them an error
    if ($find == "")
    {
    echo "<p>You forgot to enter a search term";
    exit;
    }

    // Otherwise we connect to our Database
    mysql_connect("localhost", "username", "password") or die(mysql_error());
    mysql_select_db("DBnam") or die(mysql_error());

    // We preform a bit of filtering
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");

    //And we display the results
    while($result = mysql_fetch_array($data))
    {
    echo $result['ID'];
    echo "<br>";
    echo $result['Play'];
    echo "<br>";
    echo $result['Volume'];
    echo "<br>";
    echo $result['Opened'];
    echo "<br>";
    echo $result['Performances'];
    echo "<br>";
    }

    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }

    //And we remind them what they searched for
    echo "<b>Searched For:</b> " .$find;
    }
    ?>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Looks like your query failed to me.

    Also, please use the [php][/php] tags next time you post php code to make it easier to read

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Your query is failing.. first guess would be because $field isn't set. Add or die(mysql_error()); to it to see the error.
    Last edited by Inigoesdr; 08-16-2007 at 12:35 AM. Reason: Clarifying.

  • #4
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the quick response.

    where should I put the : or die(mysql_error()); ???

  • #5
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and I think the $field is set in the form:

    <form name="search" method="post" action="<?=$PHP_SELF?>">
    Seach for: <input type="text" name="find" /> in
    <Select NAME="field">
    <Option VALUE="Play">Play</option>
    <Option VALUE="Volume">Volume</option>
    <Option VALUE="Opened">Opened</option>
    <Option VALUE="Performances">Performances</option>
    </Select>
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" />
    </form>

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $data mysql_query("SELECT * FROM users WHERE upper('".$_POST['field']."') LIKE '%$find%' ") or die("Error: ".mysql_error()); 

  • #7
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much for your help!!!

    It works!


  •  

    Posting Permissions

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