Hello all I tryed to code a little project in php/sql to learn it. I want to enter a name in the form, click search and get the results from the table of the database.
I got this form:
<form action="" method="POST">
<input type="text" name="vorname" placeholder="Hier Vorname eingeben">
</form>
I got this button:
<button type="submit" name="search" id="BirdButton" class="btn btn-primary">Search</button>
And I got this php code for output:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "test";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">Vorname</th>
<th scope="col">Nachname</th>
<th scope="col">Studiengang</th>
<th scope="col">Note</th>
</tr>
</thead>
<tbody>
<?php
echo 'BEFORE IF ISSET';
if (isset($_POST['search'])) {
echo 'SEARCH IS SET';
$vorname = $_POST['vorname'];
$query = "SELECT * FROM 'studenten' where vorname='$vorname' ";
$query_run = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($query_run)) {
?>
<tr>
<td> <?php echo $row['id'] ?></td>
<td> <?php echo $row['vorname'] ?></td>
<td> <?php echo $row['nachname'] ?></td>
<td> <?php echo $row['studiengang'] ?></td>
<td> <?php echo $row['note'] ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
At the moment, if i click my button nothing happens. Can you please help me :)?