Hi,
I am Building small shopping cart that enables customers to select books from the list and Add it to the Cart.
When i click Add Button the Cart Should Update with these things.
No of Books in the Cart.
Book Name And Quantity
I'll Submit the Entire Coding that i have currently.
My Problem is I cant Update the No of Books and Book name along with Qty.
Can anyone provide some help.
Is there any other way to Do this.
products.php
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<body>
<p><?php include('cart.p hp'); ?></p>
<p>
<?php include('result .php'); ?>
</p>
</body>
</html>
[/PHP]
result.php
[PHP]<?php
if ($_GET['cat'])
{$cat = $_GET['cat'];}
else
{$cat = "kids";}
require 'dbcon.php';
$sql="SELECT * FROM products GROUP BY p_id ORDER BY p_id asc";
$result=mysql_q uery($sql) or die("Error Occured while Searching Records : " . mysql_error());
$num=mysql_num_ rows($result);
if (mysql_num_rows ($result) == 0)
{
echo '<table width="700" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td align="left" valign="top" class="text">No Maching Result Found<br></td>
</tr></table>';
}
else
{
echo '<table width="550" border="0" cellspacing="0" cellpadding="0" >';
$colsPerRow = 3;
// width of each column in percent
$colWidth = (int)(100/$colsPerRow);
$i = 0;
while ($row = mysql_fetch_ass oc($result))
{
if ($i % $colsPerRow == 0)
{
// start a new row
echo '<tr>';
}
echo
'<td align="center">
<img src="images_pro ducts/'.$row['p_image'].'" width="154" height="154" border="0" alt="'.$row['p_image'].'"/><br>
<form action="'.$PHP_ SELF .'" method="post">
<input name="pid" type="submit" value="ADD"/>
<input name="pid" type="hidden" value="'.$row['p_id'].'"/>
</form>
</td>';
if ($i % $colsPerRow == $colsPerRow - 1)
{
echo '</tr><td align="center" valign="top">&n bsp;</td>';
}
$i += 1;
}
// print blank columns
if ($i % $colsPerRow != 0)
{
while ($i++ % $colsPerRow != 0)
{
echo '<td width="' . $colWidth . '%"> </td>';
}
echo '</tr>';
}
echo '</table>';
}
?>[/PHP]
dbcon.php
[PHP]<?
$con = mysql_connect(' localhost', 'root', 'dba') or die ("Could not connect to the Database");
mysql_select_db ('test', $con) or die (mysql_error()) ;
?>[/PHP]
cart.php
[PHP]<?php $pid = $_POST['pid'];
if($pid){
$Items = $pid;
}else{
$Items = "No Items";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<body>
<a href="view_cart .php">Your Cart<br />
</a>
<?php echo $Items;?>
</body>
</html>[/PHP]
I am Building small shopping cart that enables customers to select books from the list and Add it to the Cart.
When i click Add Button the Cart Should Update with these things.
No of Books in the Cart.
Book Name And Quantity
I'll Submit the Entire Coding that i have currently.
My Problem is I cant Update the No of Books and Book name along with Qty.
Can anyone provide some help.
Is there any other way to Do this.
products.php
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<body>
<p><?php include('cart.p hp'); ?></p>
<p>
<?php include('result .php'); ?>
</p>
</body>
</html>
[/PHP]
result.php
[PHP]<?php
if ($_GET['cat'])
{$cat = $_GET['cat'];}
else
{$cat = "kids";}
require 'dbcon.php';
$sql="SELECT * FROM products GROUP BY p_id ORDER BY p_id asc";
$result=mysql_q uery($sql) or die("Error Occured while Searching Records : " . mysql_error());
$num=mysql_num_ rows($result);
if (mysql_num_rows ($result) == 0)
{
echo '<table width="700" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td align="left" valign="top" class="text">No Maching Result Found<br></td>
</tr></table>';
}
else
{
echo '<table width="550" border="0" cellspacing="0" cellpadding="0" >';
$colsPerRow = 3;
// width of each column in percent
$colWidth = (int)(100/$colsPerRow);
$i = 0;
while ($row = mysql_fetch_ass oc($result))
{
if ($i % $colsPerRow == 0)
{
// start a new row
echo '<tr>';
}
echo
'<td align="center">
<img src="images_pro ducts/'.$row['p_image'].'" width="154" height="154" border="0" alt="'.$row['p_image'].'"/><br>
<form action="'.$PHP_ SELF .'" method="post">
<input name="pid" type="submit" value="ADD"/>
<input name="pid" type="hidden" value="'.$row['p_id'].'"/>
</form>
</td>';
if ($i % $colsPerRow == $colsPerRow - 1)
{
echo '</tr><td align="center" valign="top">&n bsp;</td>';
}
$i += 1;
}
// print blank columns
if ($i % $colsPerRow != 0)
{
while ($i++ % $colsPerRow != 0)
{
echo '<td width="' . $colWidth . '%"> </td>';
}
echo '</tr>';
}
echo '</table>';
}
?>[/PHP]
dbcon.php
[PHP]<?
$con = mysql_connect(' localhost', 'root', 'dba') or die ("Could not connect to the Database");
mysql_select_db ('test', $con) or die (mysql_error()) ;
?>[/PHP]
cart.php
[PHP]<?php $pid = $_POST['pid'];
if($pid){
$Items = $pid;
}else{
$Items = "No Items";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed Document</title>
</head>
<body>
<a href="view_cart .php">Your Cart<br />
</a>
<?php echo $Items;?>
</body>
</html>[/PHP]
Code:
CREATE TABLE `products` ( `p_id` int(10) NOT NULL auto_increment, `p_name` varchar(25) NOT NULL, `p_image` varchar(15) NOT NULL, PRIMARY KEY (`p_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1005 ; INSERT INTO `products` VALUES (1001, 'PHP MySQL Starter Kit', '1001.jpg'); INSERT INTO `products` VALUES (1002, 'ASP.Net Beginers Guide', '1002.jpg'); INSERT INTO `products` VALUES (1003, 'Learn Ajax', '1003.jpg'); INSERT INTO `products` VALUES (1004, 'Ajax Bible', '1004.jpg');
Comment