Jump to content

Mysql search not working


golyath

Recommended Posts

Hi i have written a simple searching script so that it builds a Sql statement and passes it back to another page for the results. It simply works with a check box if you want to see all items, and a drop down box if you want to serch with certain criterea and then a text box to enter the thing you are searching for...

e.g. drop down = Firstname textbox = Edward. Searching for all records where firstname = Edward.

this is the script:

    php:
    <?
        $crit=$_POST['crit'];
        $search=$_POST['search'];
       
        if($all == "all"){
            $sql="SELECT * FROM users";
            header("location:index.php?section=cPanel&control=members&ctrlMem=view&sqlCheck=$sql");
        }
        else{
            if($search == ""){
                header("location:index.php?section=error&error=missing");
            }
            else{
                $sql="SELECT * FROM users WHERE $crit = '$search'";
                //echo $sql;
                header("location:index.php?section=cPanel&control=members&ctrlMem=view&sqlCheck=$sql");
            }
        }

    ?>



this works fine if all is selected, and the Sql statement is sent back and works fine...

But... If you try to use the section where you are searching for a certian criteria, the sql errors out when usign it on the next page saying:

    php:Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource
    ?>



I have echoed out the sql when testing it to see if the sql statement is wrong, but i cant see anythign wrong with it:

SELECT * FROM users WHERE firstname = 'Edward'

If anyone can point me in the right direct it would be greatly appreciated.

Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.