Click here to Skip to main content
14,485,088 members
Rate this:
Please Sign up or sign in to vote.
See more:
( ! ) Parse error: syntax error, unexpected '$item_count' (T_VARIABLE) in C:\wamp64\www\all4you\cart.php on line 53

What I have tried:

<?php
require_once 'dbconnect.php';
include ('pages/header.php');
include ('pages/detals-menu.php');
if ($cart_id!='') {
	$cartQ=$db->query("SELECT * FROM cart WHERE id='{$cart_id}'");
	$result=mysqli_fetch_assoc($cartQ);
	$items=json_decode($result['items'],true);
	$i=1;
	$sub_total=0;
	$item_count=0;
}

?>
<div class="col-md-12">
	<div class="container">	
		<div class="row">
			<h3 class="text-center">ჩემი კალათა</h3><hr>
			<?php if ($cart_id==''): ?>
			<div class="bg-danger">
				<p class="text-center text-danger">
					კალათა ცარიელია!
				</p>
			</div>
			<?php else: ?>
				
											<?php  
							foreach ($items as $item) {
								$product_id=$item['id'];
								$productQ=$db->query("SELECT *FROM products WHERE id='{$product_id}'");
								$product=mysqli_fetch_assoc($productQ);
								$sArray=explode(',', $product['sizes']);
								foreach ($sArray as $sizeString) {
									$s=explode(':', $sizeString);
									if ($s[0]==$item['size']) {
										$available=$s[1];
									}
								}
								?>
															<?php
							$i++
							$item_count+=$item['quantity'];
							$sub_total+=($product['price'] * $item['quantity']);
							}
							$tax=TAXRATE* $sub_total;
							$tax=number_format($ax,2);
							$grand_total=$tax+$sub_total;
							?>
					<table class="table table-bordered table-condensed table-striped"><thead><tr><th>#</th><th>პროდუქცია</th><th>ფასი</th><th>რაოდენობა</th><th>ზომა</th><th>ჯამი</th></tr></thead>					<tbody><tr>									<td><?=$i;?></td>									<td><?=$product['title'];?></td>									<td><?=money($product['price']);?></td>									<td><?=$item['quantity'];?></td>									<td><?=$item['size'];?></td>									<td><?=money($item['quantity'] * $product['price']);?></td>								</tr></tbody>				</table>
				
					ჯამი
			<table class="table table-bordered table-condensed text-right"><thead class="totals-table-header"><tr><th>პროდუქციის რაოდენობა</th><th>სულ ჯამში</th><th>tax</th><th>gran total</th></tr></thead>			<tbody>				<tr>					<td><?=$item_count;  ?></td>					<td><?=money($sub_total);  ?></td>					<td><?=money($tax);  ?></td>					<td class="bg-success"><?=money($grand_total);  ?></td>				</tr>			</tbody>				</table>
			<?php endif; ?>
		</div>
	</div>
</div>
<?php
include('pages/footer.php');
?>
Posted
Updated 15-Oct-18 18:29pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

You need to initlize the
$item_count=0;
outside main code. variable out of scope error.

change this code to this

<?php
require_once 'dbconnect.php';
include ('pages/header.php');
include ('pages/detals-menu.php');

$item_count=0;
$sub_total = 0;
$grand_total = 0;
$tax = 0;

if ($cart_id!='') {
$cartQ=$db->query("SELECT * FROM cart WHERE id='{$cart_id}'");
$result=mysqli_fetch_assoc($cartQ);
$items=json_decode($result['items'],true);
$i=1;
$sub_total=0;
}

?>
   
Comments
Member 14020722 26-Oct-18 7:45am
   
not work
Rate this:
Please Sign up or sign in to vote.

Solution 3

Quote:
( ! ) Parse error: syntax error, unexpected '$item_count' (T_VARIABLE) in C:\wamp64\www\all4you\cart.php on line 53

Where is line 53 in this code ?
$productQ=$db->query("SELECT *FROM products WHERE id='{$product_id}'");

Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]

[Update]
you should try to replace
$i++
$item_count+=$item['quantity'];

with
$i++;
$item_count+=$item['quantity'];
   
v2
Comments
Member 14020722 26-Oct-18 7:45am
   
$item_count+=$item['quantity']; this is line 53
Rate this:
Please Sign up or sign in to vote.

Solution 4

It meant some kind of syntax error occurred before line 53 that caused the current line of code not being able to parse correctly. Just take a closer look at line 52, what wrong with it?
   
v2
Comments
Member 14020722 26-Oct-18 7:58am
   
tnx problem fixed i write this $i++ frong and i change on this $i++;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100