本人新手自学PHp求大神翻译下

鄢佳 发布于 2012/02/20 19:57
阅读 284
收藏 0
PHP
<?php session_start();
 $conn=mysql_connect("localhost","root","123456");
 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>

<?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","123456");
 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>";
  }
?><?php session_start();
 $conn=mysql_connect("localhost","root","123456");
 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>";
 }
?>
加载中
0
h
hhcczz

这段代码只是连接数据库,并将数据组合成为一个表单

相关知识可能对你大有帮助:

php数据库Mysql连接与操作大全(基础)

php 网页乱码终极解决方案

Win+Apache+php+MySQL开发环境配置

返回顶部
顶部