Reputation: 96
Can some one give me a solution for this error. This the error that im getting
Notice: Array to string conversion in C:\xampp\htdocs\TomisStore\functions\add_to_cart.php on line 47 Array
$newCart = new Cart();
$statement3 = $dbCon->prepare("SELECT MAX(cart_NO) FROM cart");
$statement3->execute();
if ($statement3->rowCount() > 0) {
$result2 = $statement3->fetch();
} echo $result2;
Upvotes: 0
Views: 1364
Reputation: 301
you can use var_dump($result2) or print_r($result2) and see what is in the fetch.
also you need to change your query to
"SELECT MAX(cart_NO) as cart_no FROM cart"
then you print the result to know how to access cart_no
Upvotes: 2
Reputation: 687
$result2 is an Array, not a string, echo expects a string
be Aware that $result2 is not within the same block it is defined
try var_dump($result2)
i assume, that you could echo $result2["MAX(cart_NO)"]
you could query SELECT MAX(cart_NO) as max_cart_no FROM cart
then you could echo $result2['max_cart_no'];
Upvotes: 2