未捕获的错误:在布尔值上调用成员函数bindValue()

时间:2019-08-20 15:02:04

标签: php boolean fatal-error

所以我有一个简单的预算应用程序,不断抛出此错误未捕获的错误:在C:\ xampp1 \ htdocs \ budget \ index.php:57堆栈中的布尔值上调用成员函数bindValue():#0 {main }在第57行的C:\ xampp1 \ htdocs \ budget \ index.php中抛出,这将是$ statement-> bindvalue()行的开始。

我尝试重做$ query,我尝试大写查询中的所有列。我从VALUE转到VALUES,还是一无所有。

require ('databaseconnection.php');

$amount = filter_input(INPUT_POST, 'amount',
        FILTER_VALIDATE_FLOAT);
$category = filter_input(INPUT_POST, 'category');
$date = date('Y-m-d', strtotime($_POST['date'])); 

$query = "INSERT INTO budget2019 (amount, category, date) VALUES (:amount, :category, :date)";

$statement = $conn->prepare($query);
$statement->bindValue(':amount', $amount);
$statement->bindValue(':category', $category);
$statement->bindValue(':date', $date);
$statement->execute();
$statement->closeCursor();

if ( $amount <= 0 ) {
    $message = 'Amount must be greater than zero';
    echo $message; 
}

这是数据库连接文件

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "budget";

$conn = new mysqli($servername, $username, $password, $dbName);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT SUM(amount) AS value_sum FROM budget2019";
$result = $conn->query($sql);

if ( $result->num_rows >0) {

    while($row = $result->fetch_assoc()) {
        echo "sum is : " . $row["value_sum"];
    }
} else {
    echo "0 results";
}

0 个答案:

没有答案