如何将数组产品添加到购物车php

时间:2018-06-10 08:04:21

标签: javascript php html

我想在此代码中添加“添加到购物车”我知道我是一个菜鸟程序员,但伙计们,请帮助我 和提示将不胜感激 这是创建产品和显示它的代码我使用bootstrap和PHP它大致是编写代码,但我希望你们可以帮助我,谢谢

我打算用它来建立一个电子商务网站,所以如果它的好坏也可以告诉我那个

<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap-grid.min.css" />


<?php 
$con = mysqli_connect('localhost','root','','user');

if(isset($_POST['fetch'])){

$name = $_POST['tx1'];

$desdcription = $_POST['tx2'];

$price = $_POST['tx3'];

    $image_name=$_FILES['image']['name'];

    $image_size=$_FILES['image']['size'];

    $image_type=$_FILES['image']['type'];

    $image_tmp_name=$_FILES['image']['tmp_name'];

    $move='pic/'.$image_name;

    $sql = "insert into products values

('','$name','$price','$move','$desdcription',NULL)";

    mysqli_query($con,$sql);

    move_uploaded_file($image_tmp_name,$move);

}

?>

<div class="cart"></div>

<body class="container">

<form action="" method="post" enctype="multipart/form-data">

Select Image To Upload

<br>

<input placeholder="name" type="text" name="tx1" />

<input placeholder="description" type="text" name="tx2" />

<input placeholder="price" type="text" name="tx3" />

<input type="file" name="image"/>

<br><br>

<input type="submit" name="fetch" value="Insert"/>

</form>

<?php

$query = mysqli_query($con,'select * from products');

while ($res = mysqli_fetch_assoc($query)){

?>

<div class="col-sm card" style="max-width:300px; display:inline-block">

<img class="card-img-top" src="<?php echo $res['image'] ?>" alt="Card

image cap">

 <div class="card-body">

<h5 class="card-title name"><?php echo $res['name'] ?></h5>

<h5 class="card-title"><?php echo $res['price'] ?></h5>

<p class="card-text"><?php echo $res['description'] ?></p>

<a onclick="a()" class="btn btn-primary">Add to cart</a>

 <p class="card-subtitle" style="text-align:right; color:#666;
 font-    
 size:9px">Date <?php  echo $res['Date'] ?></p>
</div>



</div>

<?php


}
?>
<script type="text/javascript" src="js/bootstrap.min.js">
</script>
<script type="application/javascript" src="js/jquery-3.3.1.min.js">        
</script>
</body>
</html>

0 个答案:

没有答案