how do i make a PHP form that pulls data from mySQL database and display it on webpage when the button is pressed?

Viewed 32

when the user keys in the Report Number into the text field and presses the submit button, a query is sent to the mySQL database and pulls the corresponding information back and displays it on the browser.

I am currently getting this error Fatal error: Uncaught Error: Cannot use object of type mysqli_result as array in C:\xampp\htdocs\index.php:36 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 36

<!DOCTYPE html>
<html>
<head>
        <title> IRTS Customer ID Query Form </title>
</head>
<body>

<h1> IRTS Customer ID Query Form </h1>
 <?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$db = "irts";

 $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
 $report_number = $_POST['report_number'];

 ?>

<form method = "POST">
    <input type = 'text' name = "report_number" placeholder = 'Enter Report Number'>
    <br><br>
    <button type = 'submit' name = 'search'> SEARCH </button>
    <?php

    $query = "SELECT customer_id FROM report_list WHERE report_number = '$report_number'";

    if(isset($_POST['search']))
    {
        
        $query_run = mysqli_query($conn, $query);

        
        while ($row = $query_run->fetch_assoc())
            {
                echo $query_run['customer_id'];
            }
    } 
    
    
        
    ?>
</form>

</body>
</html>
1 Answers

you have syntax errors

    while ($row = mysqli_fetch_assoc($query_run)){
                {
                    echo $row['customer_id'];
                }
    }
Related