By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
LahbabiGuideLahbabiGuide
  • الرئيسية
  • مزيج مِن أفكاري
    • مقالاتي
    • قصص قصيرة
    • سيناريوهات أفلام قصيرة
    • نصوص مسرحية قصيرة
  • أفكار المشاريع
  • قصص النجاح
  • أخبار تقنية
  • القرأن الكريم
Search
  • Advertise
© 2022 Zakariaelahbabi.com . Company. All Rights Reserved.
Reading: PHP Shopping Cart | Add to Cart Feature In PHP & MySQL
Share
Notification Show More
Latest News
bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap
upload-image-in-php-with-mysql-database-|-web-dev-trick
Upload Image In PHP With MySQL Database | Web Dev Trick
PHP
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap
php-age-calculator-program-|-calculate-age-in-php
PHP Age Calculator Program | Calculate Age In PHP
PHP
Aa
LahbabiGuideLahbabiGuide
Aa
  • مزيج مِن أفكاري
  • أخبار تقنية
  • تطوير الويب
  • أفكار المشاريع
Search
  • Home
    • Home 1
    • Default Home 2
    • Default Home 3
    • Default Home 4
    • Default Home 5
  • Categories
    • تطوير الويب
    • أخبار تقنية
    • أفكار المشاريع
    • مزيج مِن أفكاري
    • قصص النجاح
  • Bookmarks
  • More Foxiz
    • Sitemap
Follow US
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
php-shopping-cart-|-add-to-cart-feature-in-php-&-mysql
LahbabiGuide > تطوير الويب > PHP > PHP Shopping Cart | Add to Cart Feature In PHP & MySQL
PHP

PHP Shopping Cart | Add to Cart Feature In PHP & MySQL

admin
Last updated: 2023/03/11 at 7:37 صباحًا
By admin
Share
0 Min Read
SHARE

/* code by webdevtrick ( https://webdevtrick.com ) */

session_start();

$connect = mysqli_connect(“localhost”, “root”, “”, “cart”);

if(isset($_POST[“add_to_cart”]))

{

if(isset($_SESSION[“shopping_cart”]))

{

$item_array_id = array_column($_SESSION[“shopping_cart”], “item_id”);

if(!in_array($_GET[“id”], $item_array_id))

{

$count = count($_SESSION[“shopping_cart”]);

$item_array = array(

‘item_id’ => $_GET[“id”],

‘item_name’ => $_POST[“hidden_name”],

‘item_price’ => $_POST[“hidden_price”],

‘item_quantity’ => $_POST[“quantity”]

);

$_SESSION[“shopping_cart”][$count] = $item_array;

}

else

{

echo ”;

}

}

else

{

$item_array = array(

‘item_id’ => $_GET[“id”],

‘item_name’ => $_POST[“hidden_name”],

‘item_price’ => $_POST[“hidden_price”],

‘item_quantity’ => $_POST[“quantity”]

);

$_SESSION[“shopping_cart”][0] = $item_array;

}

}

if(isset($_GET[“action”]))

{

if($_GET[“action”] == “delete”)

{

foreach($_SESSION[“shopping_cart”] as $keys => $values)

{

if($values[“item_id”] == $_GET[“id”])

{

unset($_SESSION[“shopping_cart”][$keys]);

echo ”;

echo ”;

}

}

}

}

?>

<!DOCTYPE html>

<html>

<head>

<title>Shopping Cart In PHP and MySql | Webdevtrick.com</title>

<link rel=“stylesheet” href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css” />

</head>

<body>

<br />

<div class=“container”>

<br />

<br />

<br />

<h3 align=“center”>Shoping Cart With PHP And MySql | Source Code By <a href=“https://webdevtrick.com”>Webdevtrick.com</a></h3><br />

<br /><br />

$query = “SELECT * FROM tbl_product ORDER BY id ASC”;

$result = mysqli_query($connect, $query);

if(mysqli_num_rows($result) > 0)

{

while($row = mysqli_fetch_array($result))

{

?>

<div class=“col-md-4”>

<form method=“post” action=“index.php?action=add&id= echo $row[“id”]; ?>“>

<div style=“border:3px solid #5cb85c; background-color:whitesmoke; border-radius:5px; padding:16px;” align=“center”>

<img src=“images/ echo $row[“image”]; ?>“ class=“img-responsive” /><br />

<h4 class=“text-info”> echo $row[“name”]; ?></h4>

<h4 class=“text-danger”>$ echo $row[“price”]; ?></h4>

<input type=“text” name=“quantity” value=“1” class=“form-control” />

<input type=“hidden” name=“hidden_name” value=“ echo $row[“name”]; ?>“ />

<input type=“hidden” name=“hidden_price” value=“ echo $row[“price”]; ?>“ />

<input type=“submit” name=“add_to_cart” style=“margin-top:5px;” class=“btn btn-success” value=“Add to Cart” />

</div>

</form>

</div>

}

}

?>

<div style=“clear:both”></div>

<br />

<h3>Order Details</h3>

<div class=“table-responsive”>

<table class=“table table-bordered”>

<tr>

<th width=“40%”>Item Name</th>

<th width=“10%”>Quantity</th>

<th width=“20%”>Price</th>

<th width=“15%”>Total</th>

<th width=“5%”>Action</th>

</tr>

if(!empty($_SESSION[“shopping_cart”]))

{

$total = 0;

foreach($_SESSION[“shopping_cart”] as $keys => $values)

{

?>

<tr>

<td> echo $values[“item_name”]; ?></td>

<td> echo $values[“item_quantity”]; ?></td>

<td>$ echo $values[“item_price”]; ?></td>

<td>$ echo number_format($values[“item_quantity”] * $values[“item_price”], 2);?></td>

<td><a href=“index.php?action=delete&id= echo $values[“item_id”]; ?>“><span class=“text-danger”>Remove</span></a></td>

</tr>

$total = $total + ($values[“item_quantity”] * $values[“item_price”]);

}

?>

<tr>

<td colspan=“3” align=“right”>Total</td>

<td align=“right”>$ echo number_format($total, 2); ?></td>

<td></td>

</tr>

}

?>

</table>

</div>

</div>

</div>

<br />

</body>

</html>

You Might Also Like

Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit

Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table

Upload Image In PHP With MySQL Database | Web Dev Trick

PHP Age Calculator Program | Calculate Age In PHP

Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip

TAGGED: add to cart, Bootstrap, PHP, php and mysql, php source code, php tutorial, shopping cart, Web Development
admin مارس 11, 2023
Share this Article
Facebook Twitter Pinterest Whatsapp Whatsapp LinkedIn Tumblr Reddit VKontakte Telegram Email Copy Link Print
Previous Article php-calculator-example-with-source-code-|-basic-calculator-in-php PHP Calculator Example With Source Code | Basic Calculator in PHP
Next Article generate-random-numbers-in-php-|-numbers-in-sort-by-order Generate Random Numbers In PHP | Numbers In Sort By Order
Leave a comment Leave a comment

اترك تعليقاً إلغاء الرد

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

Stay Connected

235.3k Followers Like
69.1k Followers Follow
11.6k Followers Pin
56.4k Followers Follow
136k Subscribers Subscribe
4.4k Followers Follow
- Advertisement -
Ad imageAd image

Latest News

bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap مارس 11, 2023
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap مارس 11, 2023
upload-image-in-php-with-mysql-database-|-web-dev-trick
Upload Image In PHP With MySQL Database | Web Dev Trick
PHP مارس 11, 2023
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap مارس 11, 2023
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

[mc4wp_form id=”847″]

LahbabiGuideLahbabiGuide
Follow US

© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.

Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

[mc4wp_form]
Zero spam, Unsubscribe at any time.

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Lost your password?