Search code examples
phpmysqlnotice

filter with clickable images (input) with php / mysql


I have a number of small images (input type=image), which I want to use as a filter, e.g. if I click on the first image, in the mysql query I only want to SELECT those with the corresponding value.

It seems to work but I get a PHP notice. What am I missing?

This is what I've got so far. I enclosed screen shots of the MySql notice and table structure.

mySQL notice mySQL hats table structure

.thumbnails{height:60px;display:block;}.galery{height:200px;}
<form action="" method="post">
<input type="image" name="panama" value="panama" alt="panama" src="http://static1.cuyana.com/media/catalog/product/cache/5/gallery/0dc2d03fe217f8c83829496872af24a0/5/_/5_hat_1_2.jpg" class="thumbnails">
<input type="image" name="tophat" value="tophat" alt="tophat" src="http://www.villagehatshop.com/photos/product/giant/3509260S41/-/size-7-1-4.jpg" class="thumbnails">
</form>

<?php
$con = mysqli_connect("localhost","Melvin","") or die ("could not connect to server: " . mysqli_connect_error($con));
mysqli_select_db($con, "galerie") or die ("Could not connect to database: " . mysqli_error($con));
//$result = mysqli_query($con, "SELECT * FROM hats");
# neu ab hier

if($_POST['panama']) {
	$result = mysqli_query($con, "SELECT * FROM hats WHERE hat_cat='Panamas'");	
} elseif($_POST['tophat']) {
	$result = mysqli_query($con, "SELECT * FROM hats WHERE hat_cat='Tophats'");	
} else {
	$result = mysqli_query($con, "SELECT * FROM hats");	
}

# ende neu
while($row = mysqli_fetch_array($result)){	
	
	echo "<img src=".$row['hat_name']." &nbsp; class='galery'>";	
}
?>


Solution

  • instead of if($_POST['panama']) { use if(isset($_POST['panama'])){ that should solve it