PHP购物车代码。关于这段代码请教下各位大神,设计下表的结构和字段,让它能正确运行。
cart.php<?phpsession_start();$conn=mysql_connect("localhost","root","admin");mysql_se...
cart.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>
product.php
<?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>";
}
?>
product_index.php
<?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>";
}
?>
login.php
<?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>
谁知道表的结构和字段? 展开
<?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>
product.php
<?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>";
}
?>
product_index.php
<?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>";
}
?>
login.php
<?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个回答
2012-10-15
展开全部
消费表:【用户id,商品ID,购买数量】;
商品表:【商品id,商品名称,商品价格】
用户表:【用户ID,用户名,用户密码】
商品表:【商品id,商品名称,商品价格】
用户表:【用户ID,用户名,用户密码】
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询