I have been trying to display some test information from the database, but I’ve tried to get the information to echo. Currently the echo and the if statement is working as intended, but the variables from the database are not displaying.
This is the navbar linking code, linking with pgname and displaying title
<?php foreach($recordStorage as $pageinfo): ?> <a href="index.php?page='<?php echo $pageinfo['pgname']; ?>'" class="nav-link"><?php echo $pageinfo['title']; ?></a> <?php endforeach; ?>
This is the index display code (I removed the majority of variables to keep the code short)
<?php if(isset($_GET['page'])) { $pgname = trim($_Get['page'], "'"); $recordStorage = $connection->query("select * from scp_pages where pgname='$pgname'") or die($connection->error()); //Creates into array for display $display = $recordStorage->fetch_assoc(); $title = $display['title']; $class = $display['class']; echo " <h1>{$title}</h1> <h2> Object Class {$class}</h2> } else { echo " <h1>Welcome to this website</h1> } ?>
and finally this is the database display, from what I saw, everything was running decently
<?php $user = "database_testuser"; $password = "1234567890"; $database = "database_name"; $connection = new mysqli('localhost', $user, $password, $database) or die(mysqli_error($connection)); $recordStorage = $connection->query("select * from scp_pages") or die($connection->error()); ?>
Advertisement
Answer
The error is probably in the following statement:
$pgname = trim($_Get['page'], "'");
Instead of $_Get
, the expected syntax is in uppercase: $_GET
After changing this, dump the $pgname
var to see if it has the expected value.