parse error, unexpected $

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

parse error, unexpected $

Post by C_Calav »

help? what does this mean also.. thank you

Parse error: parse error, unexpected $ in /var/users/modelair/modelaircraft.co.nz/htdocs/cart.php on line 157

Code: Select all

<?php 

   include("include.php"); 
       
   switch($_GET["action"]) 
   { 
      case "add_item": 
      { 
         AddItem($_GET["id"], $_GET["qty"]); 
         ShowCart($rs_cart); 
         break; 
      } 
      case "update_item": 
      { 
         UpdateItem($_GET["id"], $_GET["qty"]); 
         ShowCart($rs_cart); 
         break; 
      } 
      case "remove_item": 
      { 
         RemoveItem($_GET["id"]); 
         ShowCart($rs_cart); 
         break; 
      } 
      default: 
      { 
         ShowCart($rs_cart); 
      } 
   } 

   function AddItem($itemId, $qty) 
   { 
      // Will check whether or not this item 
      // already exists in the cart table. 
      // If it does, the UpdateItem function 
      // will be called instead 
       
      // Get a connection to the database 
       
      // Check if this item already exists in the users cart table 
      $result = mysql_query("SELECT count(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); 
      $row = mysql_fetch_row($result); 
      $numRows = $row[0]; 
       
      if($numRows == 0) 
      { 
         // This item doesn't exist in the users cart, 
         // we will add it with an insert query 

         @mysql_query("INSERT INTO cart(cookieId, itemId, qty) VALUES('" . GetCartId() . "', $itemId, $qty)"); 
      } 
      else 
      { 
         // This item already exists in the users cart, 
         // we will update it instead 
          
         UpdateItem($itemId, $qty); 
      } 
   } 
    
   function UpdateItem($itemId, $qty) 
   { 
      // Updates the quantity of an item in the users cart. 
      // If the qutnaity is zero, then RemoveItem will be 
      // called instead 


      if($qty == 0) 
      { 
         // Remove the item from the users cart 
         RemoveItem($itemId); 
      } 
      else 
      { 
         mysql_query("UPDATE cart SET qty =  $qty WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); 
      } 
   } 
    
   function RemoveItem($itemId) 
   { 
      // Uses an SQL delete statement to remove an item from 
      // the users cart 


      mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); 
   } 
    
   function ShowCart() 
   { 
      // Gets each item from the cart table and display them in 
      // a tabulated format, as well as a final total for the cart 
       

      // Get a connection to the database 
       
      $totalCost = 0; 
      $result = mysql_query("SELECT * FROM cart INNER JOIN pieces ON cart.itemId=pieces.itemId WHERE cookieID='" . GetCartId() . "'"); 
      ?>
	  
	  <table>
	  <?
	  while($row = mysql_fetch_array($result))
      { 
      // Increment the total cost of all items 
      $totalCost += ($row["qty"] * $row["itemPrice"]); 
      ?> 
      
	  <tr> 
      <td width="15%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      <select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)"> 
      
	  <?php 
      for($i = 1; $i <= 20; $i++) 
      { 
      echo "<option "; 
      if($row["qty"] == $i) 
      { 
      echo " SELECTED "; 
      } 
      echo ">" . $i . "</option>"; 
      } 
      ?> 

      </select> 
      </font> 
      </td> 

      <td width="55%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      <?php echo $row["itemName"]; ?> 
      </font> 
      </td> 
      
	  <td width="20%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      $<?php echo number_format($row["itemPrice"], 2, ".", ","); ?> 
      </font> 
      </td> 
 
      <td width="10%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      <a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a> 
      </font> 
      </td> 

      </tr> 
       
     } 



</table>
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Doesn't look like you closed the ShowCart() function? That might cause some weird errors.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: parse error, unexpected $

Post by John Cartwright »

should be

Code: Select all

<?php
   include("include.php"); 
       
   switch($_GET["action"]) 
   { 
      case "add_item": 
      { 
         AddItem($_GET["id"], $_GET["qty"]); 
         ShowCart($rs_cart); 
         break; 
      } 
      case "update_item": 
      { 
         UpdateItem($_GET["id"], $_GET["qty"]); 
         ShowCart($rs_cart); 
         break; 
      } 
      case "remove_item": 
      { 
         RemoveItem($_GET["id"]); 
         ShowCart($rs_cart); 
         break; 
      } 
      default: 
      { 
         ShowCart($rs_cart); 
      } 
   } 

   function AddItem($itemId, $qty) 
   { 
      // Will check whether or not this item 
      // already exists in the cart table. 
      // If it does, the UpdateItem function 
      // will be called instead 
       
      // Get a connection to the database 
       
      // Check if this item already exists in the users cart table 
      $result = mysql_query("SELECT count(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); 
      $row = mysql_fetch_row($result); 
      $numRows = $row[0]; 
       
      if($numRows == 0) 
      { 
         // This item doesn't exist in the users cart, 
         // we will add it with an insert query 

         @mysql_query("INSERT INTO cart(cookieId, itemId, qty) VALUES('" . GetCartId() . "', $itemId, $qty)"); 
      } 
      else 
      { 
         // This item already exists in the users cart, 
         // we will update it instead 
          
         UpdateItem($itemId, $qty); 
      } 
   } 
    
   function UpdateItem($itemId, $qty) 
   { 
      // Updates the quantity of an item in the users cart. 
      // If the qutnaity is zero, then RemoveItem will be 
      // called instead 


      if($qty == 0) 
      { 
         // Remove the item from the users cart 
         RemoveItem($itemId); 
      } 
      else 
      { 
         mysql_query("UPDATE cart SET qty =  $qty WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); 
      } 
   } 
    
   function RemoveItem($itemId) 
   { 
      // Uses an SQL delete statement to remove an item from 
      // the users cart 


      mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId"); 
   } 
    
   function ShowCart() 
   { 
      // Gets each item from the cart table and display them in 
      // a tabulated format, as well as a final total for the cart 
       

      // Get a connection to the database 
       
      $totalCost = 0; 
      $result = mysql_query("SELECT * FROM cart INNER JOIN pieces ON cart.itemId=pieces.itemId WHERE cookieID='" . GetCartId() . "'"); 
      ?>
	  
	  <table>
	  <?
	  while($row = mysql_fetch_array($result))
      { 
      // Increment the total cost of all items 
      $totalCost += ($row["qty"] * $row["itemPrice"]); 
      ?> 
      
	  <tr> 
      <td width="15%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      <select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)"> 
      
	  <?php 
      for($i = 1; $i <= 20; $i++) 
      { 
      echo "<option "; 
      if($row["qty"] == $i) 
      { 
      echo " SELECTED "; 
      } 
      echo ">" . $i . "</option>"; 
      } 
      ?> 

      </select> 
      </font> 
      </td> 

      <td width="55%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      <?php echo $row["itemName"]; ?> 
      </font> 
      </td> 
      
	  <td width="20%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      $<?php echo number_format($row["itemPrice"], 2, ".", ","); ?> 
      </font> 
      </td> 
 
      <td width="10%" height="25"> 
      <font face="verdana" size="1" color="black"> 
      <a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a> 
      </font> 
      </td> 

      </tr> 
       
<?
     } //You have to have this read as php
?>


</table>
?>
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Wouldn't that brace close the while statement near the top the ShowCart() function?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

yes, and then he also needs another brace after </table>
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx guys for ur help! will try all this out when i get home from tech!
Post Reply