Когда я пытаюсь запустить этот php-файл в браузере, я получаю сообщение об ошибке: «Ошибка анализа: ошибка синтаксиса, неожиданность») , ожидая :: (T_PAAMAYIM_NEKUDOTAYIM) «в строке 50»Когда я пытаюсь запустить этот php-файл в браузере, я получаю сообщение об ошибке
У меня также есть красный на строках 54 и 55, от которых я не могу избавиться. Для этих двух строк подсказка об ошибке говорит: «Синтаксическая ошибка: ожидается : :: (»
насколько я могу видеть, все мои фигурные скобки, где они должны быть, я не знаю, что это неправильно Любые идеи Вот код:..?
<?php
//if a session is NOT already in progress for this user, start one:
if(!session_id()){
session_start();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Shopping Cart Manager</title>
<link href="css/minismall.css" rel="stylesheet">
</head>
<body>
<?php
//Check if session cart variable exists and set shortcut:
if (isset($_SESSION['cart'])) {
$cart = $_SESSION['cart'];
}
else { // $_SESSION['cart'] does NOT exist
$cart = Array();
}
include 'catalog.php';
//Check if ‘remove’ form field exists and set shortcut:
if (isset($_POST['remove'])) {
$remove = $_POST['remove'];
}
else {//$_POST['remove'] does NOT exist
$remove = Array();
}
//Initialize $totalPrice, $prodIDStr, and session ‘numItems’ variables to
//either 0 or empty string as appropriate:
$totalPrice = 0;
$prodIDStr = "";
$_SESSION[numItems] = 0;//did I initialize this session variable correctly?
//$_SESSION['numItems'] = $numItems;
//Loop through each form field (this page is called from catalog.php):
//If form field’s value (product quantity) is a positive number
//(nonzero), is NOT the submit button, AND the remove checkbox for
//removing this product has NOT been checked (do these checks in one
//condition):
while (list($productID,$qty) = each($_POST)){
if (($qty > 0) && (type != submit) && !isset(checkbox)){//LINE 50
$cat[$productID]['qty']+=$qty;//update the cart's element for
//this product with the product quantity from the form
}//LINE 54
Else if (($qty = 0) || isset(checkbox)){//if the product's quantity
//is zero or the product's remove checkbox is checked
//remove this product from the cart array:
//unset($_SESSION['cart'][$productID]);
unset($cart['productID']['qty']);
}//END OF Else if
}//END OF while loop
//Connect to your DB server and select your database:
require 'dbConnect.php';
//Loop through your cart array (foreach productID's quantity in cart):
$_SESSION['numItems'] = $cart;//Update the number of items in your cart
//Build a comma-delimited string in $prodIDStr containing the product
//ID’s of the products currently in our cart array:
$prodIDStr = implode("productID, qty", $cart);
if($_SESSION[numItems] = 0){//If cart it empty:
print "<h3>Your shopping cart is empty!</h3>\n";
}
Else{//if cart is not empty:
//remove trailing comma from $prodIDstr:
//Query DB for all products in our cart using the $prodIDStr ordering
//them by category and then by productID:
try {
$prodIDStr = $pdo->query("SELECT * FROM $cart ORDER BY $cat AND $productID");
}
catch (PDOException $e) {
$error = "Error fetching product info for category $cat: " . $e->getMessage();
include 'error.html.php';
exit();
}
//Display beginning of form which calls cart_yourname.php when submitted
//using the POST method:
?>
<form action="cart_speterson86.php" method="post">
<table>
<tr class="header">
<th>Remove</th>
<th>Image</th>
<th>Description</th>
<th>Price - US$</th>
<th>Subtotal</th>
<th>Quantity</th>
<th style="background-color: #fff"> </th>
</tr>
<?php
//
// Step through result set of products in this category and
// display each product in its own table row
//
while ($row = $itemsResult->fetch()) {
// Convert any special HTML characters to their HTML
// entities. Example: & --> &
//
// Also, strip out any HTML tags found in the data
$remove = htmlspecialchars(strip_tags($row['loc']));
$imageLocation = htmlspecialchars(strip_tags($row['loc']));
$desc = htmlspecialchars(strip_tags($row['description']));
$price = htmlspecialchars(strip_tags($row['price']));
$subTotal = htmlspecialchars(strip_tags($row['loc']));
$price = "\$" . number_format($price, 2);
$productID = strip_tags($row['prodid']);
//
// Set $qty to contain what is in our session cart array.
// If your session cart array element for this product is
// empty, set the $qty to its default value of 0.
//
if (isset($_SESSION['cart'][$productID])) {
$qty = $_SESSION['cart'][$productID];
}
else {
$qty = 0;
}
// Build and display next product row in table
print <<<TABROW
<tr>
<td><input type="checkbox" name="$remove[$productID]" value="1"></td>
<td><img src="$imageLocation" alt="groovy product $desc"></td>
<td class="desc">$desc</td>
<td class="price">$price</td>
<td class="price">$subTotal</td>
<td class="qty">
<label for="quantityForProduct$productID">Qty</label>
<input type="text" name="$productID" id="quantityForProduct$productID" value="$qty" size="3">
</td>
</tr>
TABROW;
} // end while another row in product result set
?>
<tr>
<td colspan="4" id="submitCell">
<input type="submit" name="addCart" value="Add Items to Cart">
</td>
<td><input type="submit" name="checkOut" value="Checkout"></td>
<td><input type="submit" name="updateCart" value="Update Cart"></td>
</tr>
</table>
</form>
<br>
<?php
}//END OF Else cart is not empty
?>
</body>
</html>
какие линии 50, 54 и 55? – jmadsen
Huh ... Я думал, что у stackoverflow есть функция отображения номера строки или что-то в этом роде. Подожди секунду. Я буду отмечать их комментариями. –
Удачи еще Сэму? – Mike