Hello

I have a search page with two text field and one radio button group (three buttons). You must fill in at least one value - none of the radio buttons is checked as default.

The form fields are named: productname, productgroup (radio btn) and keyword.

On the result page I have this code calling a method in class Inc_images:

PHP Code:
$productname $_POST['productname'];
        if (!isset(
$_POST['productgroup'])) {
            
$productgroup "";
        } else {
        
$productgroup $_POST['productgroup'];
        }
        
$keyword $_POST['keyword'];
        
        
$result $image->findImage($productname$productgroup$keyword);
        if (
count($result) <= 0) {
            echo 
'Finns inga bilder som matchar din sökning';
        } else {
            foreach (
$result as $item) {
                echo 
$item->pNamn;
                echo 
'<br>';
                echo 
$item->pGrupp;
                echo 
'<br>';
                echo 
$item->keywords;
                echo 
'<br>';
                echo 
'<br>';
            }
        } 
My class method looks like this:
PHP Code:
public function findImage($productname$productgroup$keyword)
    {
        try {
            
$productname "%$productname%";
            
$productgroup $productgroup;
            
$keyword "%$keyword%";
            
$sqlwhere "1 = 1 ";
            if (!empty(
$productname)) {
                
$sqlwhere .= " AND pNamn LIKE :productname";
            }
            
            if (isset(
$productgroup) || (!empty($productgroup))) {
                
$sqlwhere .= " AND pGrupp = :productgroup";
            }
            
            if (!empty(
$keyword)) {
                
$sqlwhere .= " AND keywords LIKE :keyword";
            }
            
            
$sql "SELECT * FROM images WHERE " $sqlwhere;
            
$stmt $this->pdoLink->pdoConnectLink->prepare($sql);
            
$stmt->bindParam(':productname'$productnamePDO::PARAM_STR);
            
$stmt->bindParam(':productgroup'$productgroupPDO::PARAM_STR);
            
$stmt->bindParam(':keyword'$keywordPDO::PARAM_STR);
            
$stmt->execute();
            
$result = array();
            while (
$row $stmt->fetchObject()) {
            
$result[] = $row;
        }
        return 
$result;
    }
    catch (
PDOException $e)
    {
        echo 
'Ett fel inträffade: ' $e->getMessage();
    }
    } 
For some reason the radio buttons are not ignored if none of them are selected. To have the query to return any rows I must select one of the radio buttons – which I don't want to be necessary.

Any tips on how to fix this?

Regards, Magnus