SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Drop-down box breaks MySQL script

  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,176
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Drop-down box breaks MySQL script

    I don't know why the following script is returning 0 rows. Before I added the $brandselect drop-down box to fine-tune the choice, everything was working fine.

    PHP Code:
    <?php 

    if (isset($_POST['text'])) 
        { 
        if (!
    preg_match('|^[ .0-9a-zA-Z -]+$|' $_POST['text'])) 
        exit(
    "<p class='msgbanner2'><strong>Please try again without using punctuation.</strong></p>");
        } 
    // $text is info typed into search box. 
    // $cols is the radio button checked for the number of columns desired.
    // $brandselect is the brand selected.

        
    $text $_POST['text']; 
        
    $text strtolower($text); // MAKE LOWERCASE 
        
    $text strip_tags($text); // REMOVE SYMBOLS 
        
    $text trim($text);       // REMOVE ANY EXTRA WHITE SPACE AT END OF LINE 
        
    $text htmlspecialchars($text);
        
        
    $cols $_POST['cols']; 
        
    $cols strtolower($cols); // MAKE LOWERCASE 
        
    $cols strip_tags($cols); // REMOVE SYMBOLS 
        
    $cols trim($cols);       // REMOVE ANY EXTRA WHITE SPACE AT END OF LINE 
        
    $cols htmlspecialchars($cols);

        
    $brandselect $_POST['brandselect']; 
        
    $brandselect strtolower($brandselect); // MAKE LOWERCASE 
        
    $brandselect strip_tags($brandselect); // REMOVE SYMBOLS 
        
    $brandselect trim($brandselect);       // REMOVE ANY EXTRA WHITE SPACE AT END OF LINE 
        
    $brandselect htmlspecialchars($brandselect);

    // If chose to search within single brand
    $where "WHERE (PartNo LIKE '$text' OR ItemName LIKE '%$text%' OR Descr LIKE '%$text%') AND Brand = '$brandselect'";

    // If chose to search among all brands ("allbrands" in drop-down box)
    if ($brandselect == 'allbrands')
    $where "WHERE PartNo LIKE '$text' OR ItemName LIKE '%$text%' OR Descr LIKE '%$text%'"; }

    $plq mysql_query 
    (    "SELECT Photo, PartNo, ItemName, MSRP, Descr, Brand, DateCreated
        FROM aeproducts
        
    $where
        ORDER BY DateCreated DESC" 
    ); 

    $message = array(
        
    "<p class='msgbanner1'><strong>ERROR. Please try again another time.</strong></p>",
        
    "<p class='msgbanner1'><strong>Sorry, I cannot find that information. Please check your typing and try again.</strong></p>",
        
    "<p class='msgbanner2'>You searched for <strong>$text</strong></p>",
        
    "<p class='msgbanner2'><strong>Please try again without using punctuation.</strong></p>"
        
    );
    ?>
    When $where used to be ...
    PHP Code:
    WHERE (PartNo LIKE '$text' OR ItemName LIKE '%$text%' OR Descr LIKE '%$text%') AND $Brand reedy 
    ... it worked fine. Now I want the value of "$Brand = reedy" to be dependent on a drop-down box to narrow the search further.

    Thanks!
    Steve

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a var_dump($where), see the query and make sure its valid.

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,176
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aras View Post
    Do a var_dump($where), see the query and make sure its valid.
    I did a var_dump($where) and got no message. I don't get any error messages, but the message that no rows were returned. Puzzling.

Bookmarks

Posting Permissions

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