Jump to content

Error: Parse error: syntax error, unexpected T_IF | HELP PLEASE -=[


jigsawsoul

Recommended Posts

Hey guy's i keep getting this error message below when running this script can any one tell me where i'm going wrong, what i should change please. thanks...

 

Error Message

Parse error: syntax error, unexpected T_IF in /home/jigsaws2/public_html/project/public/checkout.php on line 14

 

Checkout.php

<?php

session_start();

include('../resources/config.php');
include($config["paths"]["resources"] . 'opendb.php');
include($config["paths"]["resources"] . '_library/login.php');
include($config["paths"]["resources"] . '_library/cart.php');

$content = '

<h2>Checkout</h2>

'. if(isset($_SESSION['cart']))
   { .'
   
<form action="index.php?view=update_cart" method="post">

<table id="items">
  		<thead>
  		<tr>
	 	 	<th>Item</th>
			<th>Item Price</th>
			<th>Qty</th>
			<th>Subtotal</th>
		</tr>
 	</thead>
   		<tbody>
   		'. foreach($_SESSION['cart'] as $id => $qty): 
    	    $product = find_product($id); .'
   		<tr>
      			<td>'. echo $product['title']; .'</td>
			<td>$'. echo number_format($product['price'],2); .'</td>
		 	 <td><input type="text" size="2" name="'. echo $id .'" maxlength="2" value="'. echo $qty .'" /></td>
			<td>$'. echo number_format($product['price'] * $qty, 2); .'</td>
		</tr>
		'. endforeach; .'
	</tbody>
</table>	
<p><input type="submit" name="update" value="update" /></p>

</form>

'. }
else
{ echo '<p>your cart is empty... <a href="index.php">continue shopping</a></p>'; 
} .'

';

include($config["paths"]["resources"] . 'closedb.php'); 

?>

 

Link to comment
Share on other sites

Just before the if() you need to end the line with a ;

 

Unless you are using shorthand you can't follow a string into an if() loop. So for example...

 

$content = '

<h2>Checkout</h2>';

if(isset($_SESSION['cart']))
   {
   
        $content.= '<form action="index.php?view=update_cart" method="post">.........

 

Link to comment
Share on other sites

@teamatomic, what do you mean i've always written my sessions like this?, i'm new is there a problem with them?

 

@GetPutDelete, i tried what you said i have this error message though now

 

Error Message:

Parse error: syntax error, unexpected ';' in /home/jigsaws2/public_html/project/public/checkout.php on line 14

 

Checkout.php

<?php

session_start();

include('../resources/config.php');
include($config["paths"]["resources"] . 'opendb.php');
include($config["paths"]["resources"] . '_library/login.php');
include($config["paths"]["resources"] . '_library/cart.php');

$content = '

<h2>Checkout</h2>

'.; if(isset($_SESSION['cart']))
   { .'
   
<form action="index.php?view=update_cart" method="post">

<table id="items">
  		<thead>
  		<tr>
	 	 	<th>Item</th>
			<th>Item Price</th>
			<th>Qty</th>
			<th>Subtotal</th>
		</tr>
 	</thead>
   		<tbody>
   		'. foreach($_SESSION['cart'] as $id => $qty): 
    	    $product = find_product($id); .'
   		<tr>
      			<td>'. $product['title']; .'</td>
			<td>$'. number_format($product['price'],2); .'</td>
		 	 <td><input type="text" size="2" name="'. $id .'" maxlength="2" value="'. $qty .'" /></td>
			<td>$'. number_format($product['price'] * $qty, 2); .'</td>
		</tr>
		'. endforeach; .'
	</tbody>
</table>	
<p><input type="submit" name="update" value="update" /></p>

</form>

'. }
else
{ echo '<p>your cart is empty... <a href="index.php">continue shopping</a></p>'; 
} .'

';

include($config["paths"]["resources"] . 'closedb.php'); 

?>

 

Link to comment
Share on other sites

You are concatenating if's and foreaches into your code which is not proper syntax...in any language that I know. I would read up on proper syntax usage. In the mean time this is how it should look: (at least one way)

 

<?php

session_start();

include('../resources/config.php');
include($config["paths"]["resources"] . 'opendb.php');
include($config["paths"]["resources"] . '_library/login.php');
include($config["paths"]["resources"] . '_library/cart.php');

$content = '<h2>Checkout</h2>';
if(isset($_SESSION['cart'])) { 
$content .= '   <form action="index.php?view=update_cart" method="post">
<table id="items">
<thead>
<tr>
<th>Item</th>
<th>Item Price</th>
<th>Qty</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>';

foreach($_SESSION['cart'] as $id => $qty){ // keep sytnax similar, use one or the other (the foreach () : endforeach / if : endif; or { } 
    $product = find_product($id); 
    $content .= '
	<tr>
		<td>'. $product['title'] .'</td>
		<td>$'. number_format($product['price'],2) .'</td>
		 <td><input type="text" size="2" name="'. $id .'" maxlength="2" value="'. $qty .'" /></td>
		<td>$'. number_format($product['price'] * $qty, 2) .'</td>
	</tr>';
}

$content .= '
</tbody>
</table>
<p><input type="submit" name="update" value="update" /></p>
</form>';
echo $content;
}else {
echo '<p>your cart is empty... <a href="index.php">continue shopping</a></p>'; 
} 

include($config["paths"]["resources"] . 'closedb.php'); 
?>

 

It seems like you were combining different syntax which I bet you picked up from some templates. Like I said, read up on proper syntax, look what I fixed and why it was that way.

 

Note that I changed the foreach () : to foreach () { since you are using if () { you should keep it similar so either change the if to use the endif; format like the endforeach;. It is better not to mix and match them as it causes confusion for some people.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.