User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,915 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,324 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 786 | Replies: 2
Reply
Join Date: Sep 2006
Posts: 10
Reputation: cty is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
cty cty is offline Offline
Newbie Poster

Syntax error,plz help

  #1  
Dec 14th, 2006
PHP Parse error: parse error, unexpected $end in C:\test\kelly.php on line 118

<?php

function AddItem($itemId, $qty){

$db=new mysqli('localhost','root','','test');
$db->select_db('test');
$query="select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
$result=$db->query($query);

$row =$result->fetch_assoc();
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
$query="insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)";
$result=$db->query($query);
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($itemId, $qty);
}
}

function UpdateItem($itemId, $qty){
$query="update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId";
$result=$db->query($query);
}
function RemoveItem($itemId){
$query="delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
$result=$db->query($query);
}


function ShowCart(){


$query="select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc";
$result=$db->query($query);
while($row = $result->fetch_assoc())
{
// 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>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<tr>
<td width="70%" colspan="2">
<font face="verdana" size="1" color="black">
<a href="products.php">&lt;&lt; Keep Shopping</a>
</font>
</td>
<td width="30%" colspan="2">
<font face="verdana" size="2" color="black">
<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b>
</font>
</td>
</tr>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: Syntax error,plz help

  #2  
Dec 14th, 2006
What's line 118?

Check for matching quotation marks and matching braces. Something should be closed or ended that is not.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Join Date: Sep 2006
Location: Michigan
Posts: 22
Reputation: DennisP is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
DennisP DennisP is offline Offline
Newbie Poster

Re: Syntax error,plz help

  #3  
Dec 15th, 2006
Either you didn't give us the entire script or something is very wrong...

Either way, I changed a few things with what you did post and here's what I've got.

  1. <?php
  2.  
  3. function AddItem($itemId, $qty){
  4.  
  5. $db=new mysqli('localhost','root','','test');
  6. $db->select_db('test');
  7. $query="select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
  8. $result=$db->query($query);
  9.  
  10. $row =$result->fetch_assoc();
  11. $numRows = $row[0];
  12. if($numRows == 0)
  13. {
  14. // This item doesn't exist in the users cart,
  15. // we will add it with an insert query
  16. $query="insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)";
  17. $result=$db->query($query);
  18. }
  19. else
  20. {
  21. // This item already exists in the users cart,
  22. // we will update it instead
  23. UpdateItem($itemId, $qty);
  24. }
  25. }
  26.  
  27. function UpdateItem($itemId, $qty){
  28. $query="update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId";
  29. $result=$db->query($query);
  30. }
  31. function RemoveItem($itemId){
  32. $query="delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId";
  33. $result=$db->query($query);
  34. }
  35.  
  36.  
  37. function ShowCart(){
  38.  
  39. $query="select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc";
  40. $result=$db->query($query);
  41. while($row = $result->fetch_assoc())
  42. {
  43. // Increment the total cost of all items
  44. $totalCost += ($row["qty"] * $row["itemPrice"]);
  45. echo ' <tr>
  46. <td width="15%" height="25">
  47. <font face="verdana" size="1" color="black">
  48. <select name="'. $row["itemId"] .'" onChange="UpdateQty(this)">';
  49.  
  50. for($i = 1; $i <= 20; $i++)
  51. {
  52. echo "<option ";
  53. if($row["qty"] == $i)
  54. {
  55. echo " SELECTED ";
  56. }
  57. echo ">" . $i . "</option>";
  58. }
  59. echo '
  60. </select>
  61. </font>
  62. </td>
  63. <td width="55%" height="25">
  64. <font face="verdana" size="1" color="black">
  65. '. $row["itemName"] .'
  66. </font>
  67. </td>
  68. <td width="20%" height="25">
  69. <font face="verdana" size="1" color="black">
  70. $'. number_format($row["itemPrice"], 2, ".", ",") .'
  71. </font>
  72. </td>
  73. <td width="10%" height="25">
  74. <font face="verdana" size="1" color="black">
  75. <a href="cart.php?action=remove_item&id='. $row["itemId"] .'">Remove</a>
  76. </font>
  77. </td>
  78. </tr>
  79. <tr>
  80. <td width="100%" colspan="4">
  81. <hr size="1" color="red" NOSHADE>
  82. </td>
  83. </tr>
  84. <tr>
  85. <td width="70%" colspan="2">
  86. <font face="verdana" size="1" color="black">
  87. <a href="products.php">&lt;&lt; Keep Shopping</a>
  88. </font>
  89. </td>
  90. <td width="30%" colspan="2">
  91. <font face="verdana" size="2" color="black">
  92. <b>Total: $'. number_format($totalCost, 2, ".", ",") .'</b>
  93. </font>
  94. </td>
  95. </tr>';
  96. }
  97. }
Simple PHP Pagination - No Database Required.
If you like it, give me some props. ;)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC