0

I have been making a small webshop site with php and mysql. It is working fine locally with xampp, but after uploading it to a server some of the pages doesn't display everything.

My site is built up with div tags for header, menu, centent and footer. When viewing the source from the server, I see that the html simply stops after the content opening tag. No content, close tag or footer. But this is only for 2 pages while the rest is working.

The only thing I changed before uploading was the connection to the database, but some of the working pages uses this without any problem.

Here is the code for the add_to_cart page which i not working.

<?php
$ID = $_POST['id'];
$amount = $_POST['amount'];
if (preg_match("/^[0-9]+$/", $amount) && $amount != 0) {
    if (isset($_SESSION['cart'][$ID])) {
        $_SESSION['cart'][$ID]['quantity'] += $amount;
    } else {
        $r = @mysqli_query ($dbc, "SELECT price FROM product WHERE product_ID=$ID");
        $price = mysqli_fetch_array($r)['price'];
        echo $price;
        $_SESSION['cart'][$ID] = array('quantity' => $amount, 'price' => $price);
    }
}
header("Location: products=$ID");
?>
4

1 回答 1

2

您可能正在运行旧版本的 PHP。此行仅适用于 PHP >= 5.4,正如
dev-null-dweller提到的:

$price = mysqli_fetch_array($r)['price'];

可能更改为:

$price = mysqli_fetch_array($r);
$price = $price['price'];
echo $price;
于 2013-05-20T16:42:01.533 回答