1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: MySql Simple Search - problem

Discussion in 'Web Design & Development' started by JiminSA, Jul 30, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    I am using the following code to do a search on my db...
    PHP:
            $element $_REQUEST["element"];
            
    $criteria trim($_REQUEST["criteria"]);

            
    $row mysql_query("SELECT * FROM vehicles WHERE $element LIKE '%$criteria%'") or die(mysql_error());
    and am getting this response
    I cannot for the life of me see why - can you help?
     
  2. dukevyner

    dukevyner

    Joined:
    Nov 4, 2011
    Messages:
    787
    I've seen this error before... But don't know why when I did
     
  3. dukevyner

    dukevyner

    Joined:
    Nov 4, 2011
    Messages:
    787
    what's on line 1
     
  4. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    Line 1 is the mysql query line...
     
  5. dukevyner

    dukevyner

    Joined:
    Nov 4, 2011
    Messages:
    787
    can you post the full code? where did you specify the mysql_connect?
     
  6. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    Connect...
    PHP:
        function OpenDB()
        {
            global 
    $result;

            
    $con mysql_connect("localhost","surfwhee_jim","********************") or die(mysql_error());

            if (!
    $con)
            {
                die(
    'Could not connect: ' mysql_error());
            }
            
            
    mysql_select_db("surfwhee_vehicles"$con) or die(mysql_error());
        
        }
    (Password obscured)
    This is the CMS compatible php code...
    PHP:
        else if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "do_search")
        {
            
    OpenDB();
            
            
    $element $_REQUEST["element"];
            
    $criteria trim($_REQUEST["criteria"]);

            
    $row mysql_query("SELECT * FROM vehicles WHERE $element LIKE $criteria ORDER BY id") or die(mysql_error());

            
    BB_RedirectPage("success""Search Results for " $criteria " in " $element, array("action=managevehicles&sec_t=" BB_CreateSecurityToken("managevehicles") . "&order=" $order));
        }
        else if (isset(
    $_REQUEST["action"]) && $_REQUEST["action"] == "search")
        {
            
            
    $criteria "";
            
    $element "";
            
    $contentopts = array(
                
    "desc" => "Search the Database for specific criteria.",
                    
    "nonce" => "action",
                    
    "hidden" => array(
                        
    "action" => "do_search",
                    ),
                    
    "fields" => array(
                    
    "startrow",
                    array(
                        
    "title" => "Search in...",
                        
    "type" => "select",
                        
    "name" => "element",
                        
    "options" => array("datetime" => "Date""fullname" => "Name""make" => "Make""year" => "Year""model" => "Model",),
                        
    "width" => "150px",
                        
    "value" => BB_GetValue("element"$element),
                        
    "desc" => ""
                    
    ),
                    array(
                        
    "title" => "Search for...",
                        
    "type" => "text",
                        
    "name" => "criteria",
                        
    "width" => "200px",
                        
    "value" => BB_GetValue("criteria"$criteria),
                        
    "desc" => ""
                    
    ),
                ),
                
    "submit" => "Go",
                
    "focus" => true
            
    );

            
    BB_GeneratePage("Search For"$menuopts$contentopts);

        }
            
        
     
  7. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    Since we last comm'd I have taken out the element variable by using switch and case viz...
    PHP:
            $element $_REQUEST["element"];
            
    $criteria mysql_real_escape_string($_REQUEST["criteria"]);
            switch (
    $element)
            {
            case 
    "datetime":
                
    $row mysql_query("SELECT * FROM vehicles WHERE datetime LIKE '%$criteria%'") or die(mysql_error());
                break;
            case 
    "fullname":
                
    $row mysql_query("SELECT * FROM vehicles WHERE fullname LIKE '%$criteria%'") or die(mysql_error());
                break;
            case 
    "make":
                
    $row mysql_query("SELECT * FROM vehicles WHERE make LIKE '%$criteria%'") or die(mysql_error());
                break;
            case 
    "year":
                
    $row mysql_query("SELECT * FROM vehicles WHERE year LIKE '%$criteria%'") or die(mysql_error());
                break;
            case 
    "suburb":
                
    $row mysql_query("SELECT * FROM vehicles WHERE suburb LIKE '%$criteria%'") or die(mysql_error());
            }
    ...but it still doesn't work:(
     
  8. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    I found the problem! It was after the search in the display routine - using the wrong select variable...:eek:

    But thanks for all your help Duke(y)
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1063129