I am trying to write a website that can display information from a mySQL database using PHP.
I have set up the database connection, I believe it is doing the query but it is not displaying the query. It stops displaying data after the first variable is echoed in the code.
I attempted the query directly in mySQL and it gave me the response I wanted.
Here is the code for the HTML document:
EDIT: The value I am trying to display is an integer.
<!DOCTYPE html>
<html>
<head>
<!-- Start Link Stylesheet -->
<link rel="stylesheet" type="text/css" href="style.css" />
<!-- End Link Stylesheet-->
<!-- Start Meta Tags -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<meta author="Cole K. Motuliak">
<!-- End Meta Tags -->
<title>sumstats - view stats</title>
</head>
<body>
<header>
<h1 class="center" id="bigger">JHS IT Summer Statistics Viewpage</h1>
</header>
<h1 class="center">Welcome</h1>
<div class="center">
<?php
include 'view_stats.php';
?>
</div>
<footer>
<p class="center">© 2020 Cole K. Motuliak | <a href="mailto:cmotuliak3@gmail.com">cmotuliak3@gmail.com</a></p>
</footer>
</body>
</html>
Here is the PHP code
<?php
$servername = "localhost:3306"; // Define Server Domain Name / TCP port
$username = "sumstats_viewonly"; // Define username
$password = "*****"; // Define password, PASSWORD CHANGED FROM SCRIPT
$dbname = "sumstats_db"; // Define database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$imaged_query = "SELECT imaged FROM sumstats_table";
$tagged_query = "SELECT tagged FROM sumstats_table";
$unboxed_query = "SELECT unboxed FROM sumstats_table";
$imaged_int = $conn->query($imaged_query);
$tagged_int = $conn->query($tagged_query);
$unboxed_int = $conn->query($unboxed_query);
echo "<p >Imaged Count:", $imaged_int, "EndTest</p>";
echo "<p >Tagged Count:", $tagged_int, "EndTest</p>";
echo "<p >Unboxed Count:", $unboxed_int, "EndTest</p>";
$conn->close();
?>
If anybody could assist and tell me what I am doing wrong, please let me know. Thanks!