PHP购物车
<无详细内容>
<?php session_start();
$conn=mysql_connect("localhost","root","admin");
mysql_select_db("songyu");
//检查数组元素出现次数
function check_count($array,$element)
{
$times=0;
for($i=0;$i<count($array);$i++)
{
if($element==$array[$i])
{
$times++;
}
}
return $times;
}
if(isset($_GET["p_id"]))
{
$p_id=$_GET["p_id"];
}
$total_price=0;
array_push($_SESSION["cart"], $p_id);
$cart=$_SESSION["cart"];
echo "your cart:<br/>";
$new_array=array_count_values($cart);
foreach ($new_array as $key => $value)
{
$sql="select * from product where id='".$key."'";
$result=mysql_query($sql);
$out=mysql_fetch_array($result);
echo $out[name]."---个数:".$value."--".($out[price]*$value)."<br/>";
$total_price=$total_price+($out[price]*$value);
}
echo "<br/><br/>";
echo "-----------总价--------------<br/>";
echo $total_price;
?>
<a href="product.php">回s</a>
2. [文件] login.php ~ 374B 下载(223) 跳至 [1] [2] [3] [4] [全屏预览]
<?php session_start();
if(isset($_SESSION["user"]))
{
unset($_SESSION["user"]);
}
if(isset($_SESSION["cart"]))
{
unset($_SESSION["cart"]);
}
?>
<form action="product_index.php" method="post">
username:<input type="text" name="username"/><br/><br/>
password:<input type="password" name="password"/><br/><br/>
<input type="submit" name="submit"/>
</form>
3. [文件] product.php ~ 427B 下载(213) 跳至 [1] [2] [3] [4] [全屏预览]
<?php session_start();
$conn=mysql_connect("localhost","root","admin");
mysql_select_db("songyu");
$sql_product="select * from product";
$res=mysql_query($sql_product);
if(!isset($_SESSION["cart"]))
{
$_SESSION["cart"]=array();
}
while($out2=mysql_fetch_array($res))
{
echo "<a href='cart.php?p_id=".$out2[id]."'>".$out2[name]."</a><br/>";
echo $out2[price]."<br/>";
echo "<hr>";
}
?>
4. [文件] product_index.php ~ 424B 下载(225) 跳至 [1] [2] [3] [4] [全屏预览]
<?php session_start();
$conn=mysql_connect("localhost","root","admin");
mysql_select_db("songyu");
$sql="select * from user where username='".$_POST["username"]."' and password='".$_POST["password"]."'";
$result=mysql_query($sql);
$out=mysql_fetch_array($result);
if(!$out)
{
echo "wrong!";
}
else
{
$_SESSION["user"]=$out[id];
echo "<script>window.location.href='product.php'</script>";
}
?>
- 上一篇:php引用
- 下一篇:PHP+MYSQL+SESSION实现简单购物车功能
精彩图集
精彩文章






