So I have got this PHP program, and when I run it it works but when I click my button which references to the next .php file I get this error;
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. Notice: Undefined variable: db in C:\xampp\htdocs\school\SEDbekijken.php on line 20
Fatal error: Call to a member function query() on null in C:\xampp\htdocs\school\SEDbekijken.php on line 20
What is the problem?
Here are my PHP files:
<html lang="nl">
<head>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type ="text/css" href="boek.css">
<title>Boekenlijst van leerlingen</title>
</head>
<body>
<IMG SRC="3.png"></a>
<hr>
Op dit moment is het:
<?php echo date("d-m-Y, G:i");?>
<hr>
<br>
Wat wilt u doen?
<br>
<br>
<a href="SEDbekijken.php"><IMG SRC="1.png"></a>
<br>
<a href="SEDtoevoegen.php"><IMG SRC="2.png"></a>
</body>
</html>
When I click that ahref SEDbekijken.php i get the error
This is SEDbekijken.php:
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type ="text/css" href="boek.css">
<title>Boekenlijst</title>
</head>
<body>
<?php
// Maken van verbinding
try {
$db = new PDO('mysql:host=localhost;dbname=boekenlijst', 'root','');
}
catch(PDOException $e) {
echo $e->getMessage();
}
// De SQL opdracht
$sql = 'SELECT * FROM boeken';
$resultaat = $db->query($sql);
// De HTML-tabel opbouwen
echo '<table border = 1>';
foreach($resultaat as $row) {
echo '<tr>';
$nummer = $row['BoekNummer'];
echo '<td>'.$row['BoekNummer'].'</td>';
echo '<td>'.$row['Auteur'].'</td>';
echo '<td>'.$row['Titel'].'</td>';
echo '<td>'.$row['PlaatsNaam'].'</td>';
echo '<td>'.$row['Jaar'].'</td>';
echo '<td>'.$row['AantalPunten'].'</td>';
echo '<td>'.$row['NaamLeerling'].'</td>';
echo "<td><form action='SEDwijzigen.php' method='post'>
<input type='hidden' name='verstopt' value=$nummer>
<input type='submit' name='wijzig' value='wijzig'>
</form></td>";
echo "<td><form action='SEDverwijderen.php' method='post'>
<input type='hidden' name='verstopt' value=$nummer>
<input type='submit' name='verwijder' value='verwijder'></form></td>";
echo '</tr>';
}
echo '</table>';
// Sluiten van verbinding
$db = NULL;
?>
</body>
</html>