您的位置:首页 > 其它

一个小小的购物车系统

2015-12-17 16:06 344 查看
index.php:

<?php
session_start();
?>
<html>
<head>
<meta http-equive="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
</head>
<body background="pic/bg_02.gif">
<table align="center">
<tr>
<td width="1001" align="center">
<img src="pic/bg_01.jpg">
</td>
</tr>
<tr>
<td align="center">
<table width="791">
<tr>
<td width="200">
<img src="pic/bg_03.jpg">
</td>
<td width="579">

<?php
switch($_GET[link])
{
case "Computer";
include_once("in_1.php");
break;

case "Home Theater";
include_once("in_2.php");
break;

case "The automatic washing machine";
include_once("in_3.php");
break;

case "Digital video camera";
include_once("in_4.php");
break;

case "Mountain bike";
include_once("in_5.php");
break;

default:
include_once("in_image.php");
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>


in_1.php:

<?php
session_start();
$_SESSION[id] = "Liquid crystal dispaly#$_POST[num]parts#".($_POST[num]*900)."Yuan#30Yuan(self-care)#Gold VIP users and 88 percent discount";
?>
<html>
<head>
<title>Shopping cart</title>
</head>
<style>
body{ font-family:"楷体_GB2312"; font-size:14px;}
</style>
<body text="#FFFFFF">
<table><tr><td width="193"><img src="pic/1.jpg"></td>
<td width="282">Baby:Liquid crystal dispaly<br><br>One price for all:900Yuan<br>
<br>freight:30元(self-care)<br><br>Characteristic services:<br><br><b style="color:#FF0000">Gold users and 88 percent discount</b><br><br>remaining baby:365part<br><br>
</td></tr></table>
<?php include_once("config/config.php");?>
</body>
</html>


至于in_2.php -----in_5,php基本类似,所以就不再贴出代码了。

config.php:

<form action="" method="post">
I wang buy<input type="text" size="2" value="1" name="num">parts
<input type="submit" name"sub" value="Add shopping cart"
style="background-image:url(pic/button_2.jpg);color:red">
<input type="submit" name="sub1" value="To check out"
style="background-image:url(pic/button_3.jpg);color:red">
<input type="submit" name="sub2" value="HOme"
style="background-image:url(pic/button_1.jpg);color:red">
</form>

<?php
if($_POST[sub2])
{
echo "<script>location.href='index.php'</script>"
}
if($_POST[sub])
{
$str=explode("#",$_SESSION[id]);
include("calss/mysql.php");
$sql="inser into tb_shop(id,name,number,money,moneyother,other)
values('','$str[0]','$str[1]','$str[2]','$str[3]','$str[4]')";
if(mysql_query($sql))
{
mysql_close($conn);
echo "<script>alert('Already added to the shopping cart')</script>";
}
}
if($_POST[sub1] || $_GET['sub1'])
{
require_once("class/mysql.php");
$sq="select * from tb_shop"	;
$rs=mysql_query($sq);
?>
<form action="config/table.php" method="post">
<input type="submit" name="sub3" value="delete"
style="background-image:url(pic/button_3.jpg);color:red">
</form>
<table>
<?php
while($rst=mysql_fetch_row($rs))
for($a=0;$a<6:$a++)
{
?>
<tr><td>
<?php echo $rst[$a]?>
</td></tr>

<?php
}
?>
</table>
<a href ="config/money.php">
<img src="pic/bu.jpg"></a>
<?php
}
?>


money.php:

<html>
<head>
<title>Shopping cart</title>
</head>
<body background="../pic/bg_02.gif" style="font-family:'楷体_GB2312';
font-size:14px;" text="#FFFFFF">
<br><br><br><br><br><br>
<table align="center" border="1" bordercolor="#FFFFF" cellspacing="0" >
<tr>
<td align="center"><br>
You have successfully paid,Looking forward to your next visit!!!<br>
<form action="" method="post">
<input type="submit" name="sub7" value="Retirement"
style="background-image:url(../pic/button_2.jpg);color:#FF0000">
</form>
</td>
</tr></table>
</body>
</html>
<?php
if($_POST[sub7])
{
include("../class/mysql.php");
$sqls="truncate table tb_shop";
mysql_query($sqls);
echo "<script>window.locaton.href='../index..php'</script>"
}
?>


table.php:

<html>
<head>
<title>Shopping cart</title>
</head>
<body background="../pic/bg_02.gif" style="font-family:'楷体_GB2312'; font-size:14px;" text="#FFFFFF">
<table align="center"><tr><td>
<img src = "../pic/bg_01.jpg">
</td></tr><tr><td><table width="1001">
<tr><td width="200"><table><tr><td><table cellspacing="0" border="1"  bordercolor="red" bordercolorlight="red"><tr><td align="center"><tr><td>
<br>
<form action ="" method="post">
<input type ="text" size='20' value="Please enter to delete the commodity code" onFocus="this.value=''" name ="tt" >
<input type="submit" name="sub4" value="Check" style="background-image:url(../pic/button_2.jpg); color:#FF0000" >
<input type="submit" name="sub5" value="Back" style="background-image:url(../pic/button_2.jpg); color:#FF0000" >
</form>
</td></tr></table></td></tr><tr><td>
<img src = "../pic/bg_03.jpg">
</td></tr></table></td>
<td width="789">
</body>
</html>
<?php
require_once("../class/mysql.php");
$sq = "select * from tb_shop";
$rs = mysql_query($sq);
?>
<table>
<?php
while($rst = mysql_fetch_row($rs)){
?>
<tr><td>Commodity code:<?php echo $rst[0];?></td><td>Commodity name:<?php echo $rst[1];?></td></tr>
<tr><td>Buy numbers:<?php echo $rst[2];?><hr></td><td>ALl price:<?php echo $rst[3];?><hr></td></tr>

<?php
}
?>
</td>
</tr></table></td></tr></table>
<?php
if($_POST[sub4]){
$sqlser = "delete from tb_shop where id = '$_POST[tt]'";
if(mysql_query($sqlser)){
echo "<script>alert('Product deleted successfully')</script>";
echo "<script>window.location.href='table.php';</script>";
}
}
if($_POST[sub5]){
echo "<script>window.location.href='../index.php?link=Computer&sub1=1';</script>";
}
?>


mysql.php:

<?php
$conn = mysql_connect("localhost","root","root");
mysql_select_db("db_database02",$conn);
mysql_query("SET NAMES utf8");
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: