<!DOCTYPE html>
<html>
<head>
<meta CHARSET="UTF-8" />
<title> PHP TASK 3 RESULTS PAGE - VT211 </title>
</head>
<style>
table,
th,
td {
border: 2px Solid black
}
</style>
<body>
<?php
$servername = "dragon.kent.ac.uk";
$username = "co583";
$password = "co583";
$dbname = "co583";
//Try connecting to DB server
$DBconn = mysqli_connect($servername, $username, $password, $dbname);
try {
$dbConn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
echo "Connected succssfulluy" . "<br>";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
die();
}
?>
<?php
if (isset($_GET['cid']) && $_GET['cid'] == 'C01') {
$query = $DBConn->prepare(
"SELECT surname, forename, dob, gender FROM member WHERE clubID = 'C01' ORDER BY surname ASC, forename ASC"
);
$query->execute();
}
?>
<table>
<tr>
<th>Forename</th>
<th>Surname</th>
<th>DOB</th>
<th>Gender</th>
</tr>
<?php
while ($row = $query->fetch()) {
?>
<tr>
<td><?php echo $row['forename']; ?></td>
<td><?php echo $row['surname']; ?></td>
<td><?php echo $row['dob']; ?></td>
<td><?php echo $row['gender']; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
I'm trying to link this page to a main page which is working, however when I run the code to this page it says I have a undefined query on line 54 which I can't seem to see why it isn't working and on the same line a fatal error regarding the fetch function. Any help?
Here are the error messages;
Notice: Undefined variable: query in /teaching/proj/comp5830/php/vt211/public_html/results_page.php on line 54
Fatal error: Uncaught Error: Call to a member function fetch() on null in /teaching/proj/comp5830/php/vt211/public_html/results_page.php:54 Stack trace: #0 {main}thrown in /teaching/proj/comp5830/php/vt211/public_html/results_page.php on line 54