I am having an issue, as I am brand new to PHP. What I did was set up a search function and assigned an ID for the URL.
Basically what I want it to do is, I search for an item "puzzle", the url will grab the associated 'product_id' so I can do to details.php. URL would look like "https://sulleysells.com/SulleySells/scripts/details.php?id=3"
Then, I want to grab details such as table row names and display "product", "description", "location", etc. within details.php based on the grabbed ID from the URL.
I have tested and verified that it is grabbing the ID from the URL as I can get the ID to display using an echo element. I think the issue is somewhere within my search query, but I am not sure.
The error I am getting is "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given"
Any help would be greatly appreciated!
The way I have details.php set up is:
$servername = "localhost";
$username = "u449450474_inventory";
$password = "*******";
$db = "u449450474_products";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$query = "SELECT * FROM `inventory` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo $row['id'];
echo $row['products'];
echo $row['description'];
echo $row['location'];
}
The way I have the search set up (which is called through a different page using a element.:
$servername = "localhost";
$username = "u449450474_inventory";
$password = "*******";
$db = "u449450474_products";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$sql = "select * from `inventory` where `product` like '%" . $search . "%'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc() ){
echo "<tr><td>"."<a href='/WebsiteName/scripts/details.php?id={$row['product_id']}'>Update</a>"."</td><td>" .$row['product']. "</td><td>" .$row['description']. "</td></tr>";
}
} else {
echo "0 records";
}
$conn->close();