Jump to content

Parse error: syntax error, unexpected T_VARIABLE, expecting ';'


ameen

Recommended Posts

Hi, I could not solve this problem as stated below.

 

 

Parse error: syntax error, unexpected T_VARIABLE, expecting ';' in C:\Program Files\EasyPHP 2.0b1\www\library\config.php on line 71

 

Appreciate if anyone solve it. Line 71 I have bold it.  Thanks

 

if (!get_magic_quotes_gpc()) {

 

if ( (isset($_POST)) && (!isset($_POST['txtQty']))  && (!isset($_POST['hidCartId']))    &&  (!isset($_POST['hidProductId']))  )

{

foreach ($_POST as $key => $value)

{

$_POST[$key] =  trim(addslashes($value));

}

}

 

//  txtQty[]

 

if ( isset($_POST['txtQty'])) 

{

$countQty = count($_POST['txtQty']);

for($i = 0; $i < $countQty; $i++)

{

 

    $valQty = $_POST['txtQty'][$i];

$_POST['txtQty'][$i] =  trim(addslashes($valQty));

}

}

 


if (!get_magic_quotes_gpc()) {

   if ( (isset($_POST)) && (!isset($_POST['txtQty']))  && (!isset($_POST['hidCartId']))    &&  (!isset($_POST['hidProductId']))  )
   {
      foreach ($_POST as $key => $value)
      {
      $_POST[$key] =  trim(addslashes($value));
      }
   }

//   txtQty[]

   if ( isset($_POST['txtQty'])) 
    {
      $countQty = count($_POST['txtQty']);
      for($i = 0; $i < $countQty; $i++)
       {

          $valQty = $_POST['txtQty'][$i];
      $_POST['txtQty'][$i] =  trim(addslashes($valQty));
      }
   }

 

Seems fine. Show us the exact line. And post the first few lines above it. Remember to comment which one is the line number that the error is appearing on so that we can see it.


if (!get_magic_quotes_gpc()) {

   if ( (isset($_POST)) && (!isset($_POST['txtQty']))  && (!isset($_POST['hidCartId']))    &&  (!isset($_POST['hidProductId']))  )
   {
      foreach ($_POST as $key => $value)
      {
      $_POST[$key] =  trim(addslashes($value));
      }
   }

//   txtQty[]

   if ( isset($_POST['txtQty'])) 
    {
      $countQty = count($_POST['txtQty']);
      for($i = 0; $i < $countQty; $i++)
       {

          $valQty = $_POST['txtQty'][$i];
      $_POST['txtQty'][$i] =  trim(addslashes($valQty));
      }
   }

 

Seems fine. Show us the exact line. And post the first few lines above it. Remember to comment which one is the line number that the error is appearing on so that we can see it.

 

The OP has:

 


if (!get_magic_quotes_gpc()) {

   if ( (isset($_POST)) && (!isset($_POST['txtQty']))  && (!isset($_POST['hidCartId']))    &&  (!isset($_POST['hidProductId']))  )
   {
      foreach ($_POST as $key => $value)
      {
      $_POST[$key] =  trim(addslashes($value));
      }
   }

//   txtQty[]

   if ( isset($_POST['txtQty'])) 
    {
      $countQty = count($_POST['txtQty']);
      for($i = 0; $i < $countQty; $i++){ //its this line here!!!!

          $valQty = $_POST['txtQty'][$i];
      $_POST['txtQty'][$i] =  trim(addslashes($valQty));
      }
   }

ok try

$i = 0;

for($i < $countQty; $i++)

 

for loops take 3 expressions. That would most likely result in an error.

 

Try commenting things above it out ameen, try to track the error down. Because I can't see anything.

When I changed the code as below :

 

$i = 0;

for($i < $countQty; $i++)  // This is line 72 in config.php

 

It gives the following message.

 

Parse error: syntax error, unexpected ')', expecting ';' in C:\Program Files\EasyPHP 2.0b1\www\library\config.php on line 72

The config.php is below that is causing the error,  the file that calls this file is cart.php.  I have included below.

Config.php

<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);

// start the session
session_start();

// database connection config
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';

$dbName = 'plaincart';

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);






define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);

// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR',  'images/product/');

// some size limitation for the category
// and product images

// all category image width must not 
// exceed 75 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 75);

// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH',     true);

// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);

// the width for product thumbnail
define('THUMBNAIL_WIDTH',         75);

if (!get_magic_quotes_gpc()) {

if ( (isset($_POST)) && (!isset($_POST['txtQty']))  && (!isset($_POST['hidCartId']))    &&  (!isset($_POST['hidProductId']))  ) 
{
	foreach ($_POST as $key => $value) 
	{
	$_POST[$key] =  trim(addslashes($value));
	}
}

//   txtQty[]

if ( isset($_POST['txtQty']))  
	{
	$countQty = count($_POST['txtQty']);
	$i = 0;
	[color=orange][b]for($i < $countQty; $i++) // [/b][/color][color=orange][b]This line is causing the error[/b][/color]
	 { 

    		$valQty = $_POST['txtQty'][$i];
	$_POST['txtQty'][$i] =  trim(addslashes($valQty));
	} 
}

// hidCartId[]

if ( isset($_POST['hidCartId']))  
	{
	for( $i = 0; $i < count($_POST['hidCartId']); $i++) 
{

    		$valHidCartId = $_POST['hidCartId'][$i];
	$_POST['hidCartId'][$i] =  trim(addslashes($valHidCartId ));
	} 

}


// hidProductId[]

if ( isset($_POST['hidProductId']))  
	{
	for($i = 0; $i < count($_POST['hidProductId']); $i++) 

	{

    		$valHidProductId = $_POST['hidProductId'][$i];
	$_POST['hidProductId'][$i] =  trim(addslashes($valHidProductId ));
	} 
}	



// remove temporarily

//	if (isset($_POST)) {
//		foreach ($_POST as $key => $value) {
//			$_POST[$key] =  trim(addslashes($value));
//		}
//	}

if (isset($_GET)) {
	foreach ($_GET as $key => $value) {
		$_GET[$key] = trim(addslashes($value));
	}
}	
}


require_once 'database.php';
require_once 'common.php';

// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();
?>

 

Cart.php codes are included below.  I am using POST method for the form elements.  The codes in config.php works fine for all values of POST.  But for Input Array txtQty, hidCartId & hidProductId it is causing array to string conversion error. 

 

<input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);">

<input name="hidCartId[]"  type="text"  value="<?php echo $ct_id; ?>">

  <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>">

 

I will try to use mysql_real_escape_string  to solve the problem.

 

Thanks for the feedbacks and help.

 

 

 

<?php
require_once 'library/config.php';
require_once 'library/cart-functions.php';

$action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view';

switch ($action) {
case 'add' :
	addToCart();
	break;
case 'update' :
	updateCart();
	break;	
case 'delete' :
	deleteFromCart();
	break;
case 'view' :
}

$cartContent = getCartContent();
$numItem = count($cartContent);

$pageTitle = 'Shopping Cart';
require_once 'include/header.php';

// show the error message ( if we have any )
displayError();

if ($numItem > 0 ) {
?>
[b][color=yellow]<form action="<?php echo $_SERVER['PHP_SELF'] . "?action=update"; ?[/color][/b]>" method="post" name="frmCart" id="frmCart">
<table width="780" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
  <tr class="entryTableHeader"> 
   <td colspan="2" align="center">Item</td>
   <td align="center">Unit Price</td>
   <td width="75" align="center">Quantity</td>
   <td align="center">Total</td>
  <td width="75" align="center"> </td>
</tr>
<?php
$subTotal = 0;
for ($i = 0; $i < $numItem; $i++) {
extract($cartContent[$i]);
$productUrl = "index.php?c=$cat_id&p=$pd_id";
$subTotal += $pd_price * $ct_qty;
?>
<tr class="content"> 
  <td width="80" align="center"><a href="<?php echo $productUrl; ?>"><img src="<?php echo $pd_thumbnail; ?>" border="0"></a></td>
  <td><a href="<?php echo $productUrl; ?>"><?php echo $pd_name; ?></a></td>
   <td align="right"><?php echo displayAmount($pd_price); ?></td>
  <td width="75">[b][color=pink][font=Verdana]<input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);">
  <input name="hidCartId[]"  type="text"  value="<?php echo $ct_id; ?>">
  <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>">[/font][/color][/b]
  </td>
  <td align="right"><?php echo displayAmount($pd_price * $ct_qty); ?></td>
  <td width="75" align="center"> <input name="btnDelete" type="button" id="btnDelete" value="Delete" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" class="box"> 
  </td>
</tr>
<?php
}
?>
<tr class="content"> 
  <td colspan="4" align="right">Sub-total</td>
  <td align="right"><?php echo displayAmount($subTotal); ?></td>
  <td width="75" align="center"> </td>
</tr>
<tr class="content"> 
   <td colspan="4" align="right">Shipping </td>
  <td align="right"><?php echo displayAmount($shopConfig['shippingCost']); ?></td>
  <td width="75" align="center"> </td>
</tr>
<tr class="content"> 
   <td colspan="4" align="right">Total </td>
  <td align="right"><?php echo displayAmount($subTotal + $shopConfig['shippingCost']); ?></td>
  <td width="75" align="center"> </td>
</tr>  
<tr class="content"> 
  <td colspan="5" align="right"> </td>
  <td width="75" align="center">

[color=red][font=Verdana][b]<input name="btnUpdate" type="submit" id="btnUpdate" value="Update Cart"  class="box"></td>[/b][/font][/color]
</tr>
</table>
</form>
<?php
} else {

?>
<p> </p><table width="550" border="0" align="center" cellpadding="10" cellspacing="0">
<tr>
  <td><p align="center">You shopping cart is empty</p>
   <p>If you find you are unable to add anything to your cart, please ensure that 
    your internet browser has cookies enabled and that any other security software 
    is not blocking your shopping session.</p></td>
</tr>
</table>
<?php
}

$shoppingReturnUrl = isset($_SESSION['shop_return_url']) ? $_SESSION['shop_return_url'] : 'index.php';
?>
<table width="550" border="0" align="center" cellpadding="10" cellspacing="0">
<tr align="center"> 
  <td><input name="btnContinue" type="button" id="btnContinue" value="<< Continue Shopping" onClick="window.location.href='<?php echo $shoppingReturnUrl; ?>';" class="box"></td>
<?php 
if ($numItem > 0) {
?>  
  <td><input name="btnCheckout" type="button" id="btnCheckout" value="Proceed To Checkout >>" onClick="window.location.href='checkout.php?step=1';" class="box"></td>
<?php
}
?>  
</tr>
</table>
<?php
require_once 'include/footer.php';
?>

 

ok try

$i = 0;

for($i < $countQty; $i++)

 

for loops take 3 expressions. That would most likely result in an error.

 

Try commenting things above it out ameen, try to track the error down. Because I can't see anything.

 

Don't try what jesushax suggested. Your for loop was fine the way it was.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.