简体   繁体   中英

ERROR: Trying to access array offset on value of type bool in

I have a fuction in php class:

public function details($id) {
        try {
            $sql = "SELECT * FROM khoa WHERE ma_khoa = :ma";
            $stmt = $this->db->prepare($sql);
            $stmt->bindparam(":ma", $ma);
            $stmt->execute();
            $result = $stmt->fetch();
            return $result; 
        } catch (Exception $e) {
            echo $e->getMessage();
            return false;
        }
    }

then, I use this function in form:

<form method="POST" action="update_post.php"> 
    <div class="row100">
        <div class="col">
            <div class="inputBox">
                <input type="text">
                <input type="text" value="<?php echo $kh['ma_khoa']; ?>" name="makhoa">
                <span class="text">Mã khoa</span>
                <span class="line"></span>
            </div>
        </div>
    </div>
</form>

With $kh = $khoa->details($id); and $khoa is variable to connect to database.

But i get this notice:

在此处输入图片说明

Can you explain for me about this error and the way to solved this?

As your log said, your call $kh = $khoa->details($id); had $kh = false So please recheck and debug your details function.

And of course, false is a bool value , cannot be access with as an array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM