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
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Jul 25, 2004 12:03 am
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>
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Jul 25, 2004 12:08 am
whoops forgot the error
Parse error: parse error, unexpected $ in /var/users/modelair/modelaircraft.co.nz/htdocs/products.php on line 61
lolpix
Forum Commoner
Posts: 41 Joined: Sat Jul 17, 2004 2:20 am
Post
by lolpix » Sun Jul 25, 2004 12:36 am
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.
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Jul 25, 2004 12:38 am
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!
lolpix
Forum Commoner
Posts: 41 Joined: Sat Jul 17, 2004 2:20 am
Post
by lolpix » Sun Jul 25, 2004 12:43 am
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>
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Sun Jul 25, 2004 12:47 am
it does help.. thank you so much. will look through code see what you done