<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "restauracja";

$io = 0;

if(isset($_POST["n"])){
	$io = 1;
}
if(isset($_POST["c"])){
	$io = 2;
}



// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Błąd połączenia: " . mysqli_connect_error());
}

if($io == 1){
	$sql = "SELECT * FROM dania WHERE `nazwa` LIKE '%". $_POST["n"] ."%'";
}elseif($io == 2){
	$sql = "SELECT * FROM dania WHERE `cena` = '". $_POST["c"] ."'";
}else{
	$sql = "SELECT * FROM dania";
}

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
  
  echo "<table border=1> <tr><th>nazwa</th><th>cena</th></tr>";
 
  while($row = mysqli_fetch_assoc($result)) {
    echo  "<tr><td>" . $row["nazwa"]. "</td><td>" . $row["cena"]. "</td></tr>";
  }
  echo "</table>";
} else {
  echo "brak wyników";
}

mysqli_close($conn);
?>

<br  /><br  />

<form action="" method="POST">
	<input type="text" name="n" />
	<button type="submit" >pokaż nazwę</button>
</form>

<form action=""  method="POST">
	<input type="text" name="c" />
	<button type="submit" >pokaż cenę</button>
</form>