I have set the php as below aims at accessing mysql database and then get the column of id(set as pid). However, the page can access to the database, but it failed to access the table.
<?php
$con = mysqli_connect('localhost','root','password','adeline');
if ($con) {
echo 'Connection Successfully';
}else{
echo 'Connection Failed';
}
if (isset($_GET['pid'])) {
// Prepare statement and execute, prevents SQL injection
$stmt = $con->prepare('SELECT * FROM product WHERE pid = ?');
$stmt->execute([$_GET['pid']]);
// Fetch the product from the database and return the result as an Array
$product = $stmt->fetch_assoc();
// Check if the product exists (array is not empty)
if (!$product) {
// Simple error to display if the id for the product doesn't exists (array is empty)
exit('Product does not exist!');
}
} else {
// Simple error to display if the id wasn't specified
exit('Product does not exist isset!');
}
?>
it shows "Connection SuccessfullyProduct Does Not Exist Isset!" when I run the page. I did add the product table in phpmyadmin and pid exists in the column. I don't understand why it cannot access to product table to get the pid I want. This is my product table in my database.