Twój "pattern" sql wygląda tak: (pewna część)
$sql = "SELECT * FROM old_studenci WHERE szukanie='0' '$imie_z'
niech zmienna $imie_z przyjmie wartość z $_POST['imie'] - Stanisław
to po
$imie_z = "AND imie='$imie'";
mamy
$sql = "SELECT * FROM old_studenci WHERE szukanie='0' 'And imie='Stanisław''
i tak z resztą zmiennych z końcówką _z, czyli zdecydowanie tworzy się nie do końca prawidłowa forma zapytania sql.
po usunięciu tych apostrofów, powinno zadziałać.
$sql = "SELECT * FROM old_studenci WHERE szukanie='0' $imie_z $nazwisko_z "
wtedy mam
$sql = "SELECT * FROM old_studenci WHERE szukanie='0' And imie='Stanisław' AND nazwisko='Ruszkowski' "
Propozycje zmian.
Strona z formularzem:
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>VOLANS 2.0</title>
<link href="style/form.css" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
#basic {
margin-bottom: 1em;
}
#basic input[type="submit"] {
margin: 0.5em 0;
}
#form label {
display: block;
margin-top: 0.5em;
}
#form input[type="submit"] {
display: block;
margin: 1.5em 0;
}
</style>
</head>
<body>
<div id="nazwa">
VOLANS 2.O
</div>
<div id="basic" >
<form action="s_g.php">
<input type="submit" value="Wstecz">
</form>
</div>
<div id="form">
<form action="szukanie.php" method="post">
<label for="imie">Imie:</label>
<input type="text" name="imie">
<label for="nazwisko">Nazwisko:</label>
<input type="text" name="nazwisko">
<label for="indeks">Indeks:</label>
<input type="text" name="indeks">
<label for="rok">Rok:</label>
<input type="text" name="rok">
<label for="kierunek">Kierunek:</label>
<input type="text" name="kierunek">
<label for="semestr">Semestr:</label>
<input type="text" name="semestr">
<label for="tryb">Tryb:</label>
<input type="text" name="tryb">
<label for="jezyk">Jezyk:</label>
<input type="text" name="jezyk">
<input type="submit" value="szukaj">
</form>
</div>
</body>
</html>
Strona z wynikiem
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//var_dump($_POST);
$sql_where = '';
foreach ($_POST as $key => $value) {
if (! empty($_POST[$key])) {
$sql_where .= " AND {$key}='{$value}'";
}
}
if (! empty($sql_where)) {
require_once "connect.php";
$connect = @new mysqli($host, $db_user, $db_password, $db_name);
$sql = "SELECT * FROM old_studenci WHERE szukanie='0'{$sql_where}";
if ($result = $mysqli->query($sql)) {
$count_students = $result->num_rows;
$rows = '';
while($row = $result->fetch_assoc()) {
$rows .= "<tr><td>{$row['id']}</td>"
. "<td>{$row['imie']}</td>"
. "<td>{$row['nazwisko']}</td>"
. "<td>{$row['indeks']}</td>"
. "<td>{$row['rok']}</td>"
. "<td>{$row['kierunek']}</td>"
. "<td>{$row['semestr']}</td>"
. "<td>{$row['tryb']}</td>"
. "<td>{$row['jezyk']}</td></tr>";
}
} else {
$count_students = 0;
$rows = noResultsFoundMessage();
}
$mysqli->close();
} else { // if (! empty($sql_where))
$count_students = 0;
$rows = noResultsFoundMessage();
}
} else { // ($_SERVER['REQUEST_METHOD'] == 'POST')
$count_students = 0;
$rows = noResultsFoundMessage();
}
function noResultsFoundMessage() {
return '<tr>'
. '<td colspan="9">Nie znaleziono wyników dla podanych kryteriów</td>'
. '</tr>';
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Wszyscy studenci</title>
<style>
* {
box-sizing: border-box;
}
#container {
}
#nazwa {
width: 1000px;
font-size: 50px;
text-align: center;
margin-left: auto;
margin-right: auto;
}
#tabelka {
padding: 0.1em;
}
#tabelka table {
width: 1000px;
margin-left: auto;
margin-right: auto;
border: 1px solid rgba(124,124,124,0.8); /* #7c7c7c */
border-collapse: separate;
border-spacing: 0px; /* cellspacing="0" */
}
#tabelka caption {
text-align: left;
padding: 0.5em 1em;
}
#tabelka table tr:nth-child(2n+1) {
background-color: rgba(247,247,247,1); /* #f7f7f7 */
}
#tabelka table tr:nth-child(2n+2) {
background-color: rgba(235,235,235,1); /* #ebebeb */
}
#tabelka table tr:hover {
background-color: rgba(242,236,216,1); /* #f2ecd8 */
/* background-color: rgba(231,220,240,1); /* #e7dcf0 */ */
}
#tabelka table th {
padding: 0px; /* cellpadding="0" */
text-align: center;
background-color: rgba(229,229,229,1); /* #e5e5e5 */
border-bottom: 1px solid rgba(124,124,124,0.8); /* #7c7c7c */
}
#tabelka table td {
padding: 0.5em 0;
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<div id="tabelka">
<table>
<caption><?php echo $count_students; ?> Studentów.</caption>
<thead>
<th>Lp.</th>
<th>Imie</th>
<th>Nazwisko</th>
<th>Numer Indeksu</th>
<th>Rok</th>
<th>Kierunek</th>
<th>Semestr</th>
<th>Tryb</th>
<th>Jezyk</th>
</thead>
<tbody>
<?php echo $rows; ?>
</tbody>
</table>
</div>
</div>
</body>
</html>
została ewentualnie jeszcze jedna rzecz do zrobienia, Twój kod i Moja propozycja zmian (chodzi o Strona z wynikiem) skrypt nie jest "odporny" na ewentualny atak "SQL Injection", ale nie chciałem Tobie na tym etapie "rozbudowywać" kodu (co mogło by utrudnić ewentualne zrozumienie go) to można dodać "później"