0

Trying to connect database where you can add/delete/update records for a bookstore, when opening webpage the data base does not load with the webpage this is the code for my view.php

<?php

// connect to the database

include('connect-db.php');

// get results from database
$query = "SELECT * FROM Product;";
$result = mysqli_query($conn, $query); #or die(mysqli_error());

if(mysqli_num_rows($result) > 0){
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
        echo "<tr>";
        echo '<td>' . $row['id'] . '</td>';
        echo '<td>' . $row['product_Name'] . '</td>';
        echo '<td>' . $row['description'] . '</td>';
        echo '<td>' . $row['price'] . '</td>';
        echo '<td>' . $row['stock'] . '</td>';
        echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
        echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
        echo "</tr>";
    }
} 

Code for connect-db:

<?php
    $servername = "127.0.0.1";
    $username = "s4917077";
    $password = "0e671ada8c93cd0784960c31e58686f";

    // Create connection
    $conn = new mysqli($servername, $username, $password);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    echo "Connected successfully";
?>
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
A.Brooke
  • 17
  • 5
  • Show `connect-db.php` code too. and change line:- `$result = mysqli_query($conn, $query); #or die(mysqli_error());` to `$result = mysqli_query($conn, $query) or die(mysqli_error($conn));` and check – Alive to die - Anant Dec 06 '17 at 13:20
  • What's the *entire* error message? – John Conde Dec 06 '17 at 13:21
  • PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/html/bookstore/view.php on line 33 - line 33 is $query – A.Brooke Dec 06 '17 at 13:29

0 Answers0