Mengapa Saya Mendapat 'Panggil ke Fungsi Ahli execute() pada Boolean' dalam rent.php?

Susan Sarandon
Lepaskan: 2024-11-14 21:00:03
asal
951 orang telah melayarinya

Why Am I Getting

Call to a Member Function execute() on Boolean in rent.php

In PHP programming, you may encounter the error "Call to a member function execute() on boolean" when working with MySQL databases and executing prepared statements using mysqli_prepare and mysqli_execute. This error typically indicates a problem with the SQL statement or the type of data being passed to the execute() function.

In your case, you mentioned that you received this error when executing the following line in your rent.php script:

$req->execute(array($_POST['email'], $_POST['msg_text']));
Salin selepas log masuk

mysqli_prepare() returns a boolean value (TRUE/FALSE) to indicate whether the SQL statement was prepared successfully. If the statement is not prepared successfully, you should check for errors using mysqli_error() to get more information.

In your case, the error occurred because there is a typo in the SQL statement. You have "INSET" instead of "INSERT" in the SQL statement:

$req = $conn->prepare('INSET INTO renter (email, msg_text) VALUES(?, ?)');
Salin selepas log masuk

Once you correct the typo to "INSERT", your code should execute as intended and insert the data into the renter table in your database. Remember to always check for errors using mysqli_error() after executing mysqli_prepare() to ensure the statement was prepared successfully.

Atas ialah kandungan terperinci Mengapa Saya Mendapat 'Panggil ke Fungsi Ahli execute() pada Boolean' dalam rent.php?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan