Page 1 of 1

shopping cart tutorial help

Posted: Sun Jul 25, 2004 12:03 am
by C_Calav
hey guys, just following a tutorial off Dev Articles for a shopping cart. although i am stuck there code gives this error. what is wrong here please?

Code: Select all

<?php 

include("db.php"); 

// Get a connection to the database 
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); 
$result = mysql_query("select * from items order by itemName asc"); 
?> 



<?php 
while($row = mysql_fetch_array($result)) 
{ 
?> 

<html>
<body>
<table> 
 
 

<tr> 
<td width="30%" height="25"> 
<font face="verdana" size="1" color="black"> 
<?php echo $row["itemName"]; ?> 
</font> 
</td> 
<td width="10%" height="25"> 
<font face="verdana" size="1" color="black"> 
$<?php echo $row["itemPrice"]; ?> 
</font> 
</td> 
<td width="50%" height="25"> 
<font face="verdana" size="1" color="black"> 
<?php echo $row["itemDesc"]; ?> 
</font> 
</td> 
<td width="10%" height="25"> 
<font face="verdana" size="1" color="black"> 
<a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a> 
</font> 
</td> 
</tr> 
<tr> 
<td width="100%" colspan="4"> 
<hr size="1" color="red" NOSHADE> 
</td> 
</tr> 


<tr> 
<td width="100%" colspan="4"> 
<font face="verdana" size="1" color="black"> 
<a href="cart.php">Your Shopping Cart >></a> 
</font> 
</td> 
</tr> 
</table> 
</body> 
</html>

Posted: Sun Jul 25, 2004 12:08 am
by C_Calav
whoops forgot the error

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

Posted: Sun Jul 25, 2004 12:36 am
by lolpix
No offense, but there is SO much wrong this script I am not sure where to begin. For starters, you have started a "while" loop but have not closed it. To make matters worse, even if you had closed it, your while loop is creating a new page on every iteration by printing...

<html>
<body>
<table>
<blah><blah><blah>


...on every pass the loop makes.

Posted: Sun Jul 25, 2004 12:38 am
by C_Calav
thanx for the reply.

firstly, i put the

<html>
<body>
<table>

in, wrong place.

so no ending to the while loop aye. ill have a look at it.

this script straight from http://www.devarticles.com/c/a/MySQL/Bu ... d-MySQL/3/

seemed like the best one i could find!

Posted: Sun Jul 25, 2004 12:43 am
by lolpix
Does this help at all?

Code: Select all

<?php


include("db.php"); 

// Get a connection to the database 
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); 
$result = mysql_query("select * from items order by itemName asc"); 
?> 

<html> 
<body> 
<table> 

<?php 

while($row = mysql_fetch_array($result)) 
{ 

?> 

<tr> 
    <td width="30%" height="25"> 
        <font face="verdana" size="1" color="black"> 
            <?php echo $row["itemName"]; ?> 
        </font> 
    </td> 

    <td width="10%" height="25"> 
        <font face="verdana" size="1" color="black"> 
            $<?php echo $row["itemPrice"]; ?> 
        </font> 
    </td> 

    <td width="50%" height="25"> 
        <font face="verdana" size="1" color="black"> 
            <?php echo $row["itemDesc"]; ?> 
        </font> 
    </td> 

    <td width="10%" height="25"> 
        <font face="verdana" size="1" color="black"> 
            <a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a> 
        </font> 
    </td> 
</tr> 


<tr> 
    <td width="100%" colspan="4"> 
        <hr size="1" color="red" NOSHADE> 
    </td> 
</tr> 

<?php

}

?>

<tr> 
    <td width="100%" colspan="4"> 
        <font face="verdana" size="1" color="black"> 
            <a href="cart.php">Your Shopping Cart >></a> 
        </font> 
    </td> 
</tr> 

</table> 
</body> 
</html>

Posted: Sun Jul 25, 2004 12:47 am
by C_Calav
it does help.. thank you so much. will look through code see what you done :)