Professional Documents
Culture Documents
PHP
PHP
php
session_start();
//error_reporting(0);
include('includes/config.php');
if (strlen($_SESSION['aid']==0)) {
header('location:logout.php');
} else{
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "add":
if(!empty($_POST["quantity"])) {
$pid=$_GET["pid"];
while($productByCode=mysqli_fetch_array($result)){
$itemArray = array($productByCode["id"]=>array('catname'=>$productByCode["CategoryName"],
'compname'=>$productByCode["CompanyName"], 'quantity'=>$_POST["quantity"],
'pname'=>$productByCode["ProductName"],
'price'=>$productByCode["ProductPrice"],'code'=>$productByCode["id"]));
if(!empty($_SESSION["cart_item"])) {
if(in_array($productByCode["id"],array_keys($_SESSION["cart_item"]))) {
if($productByCode["id"] == $k) {
if(empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
} else {
$_SESSION["cart_item"] = $itemArray;
break;
case "remove":
if(!empty($_SESSION["cart_item"])) {
if($_GET["code"] == $k)
unset($_SESSION["cart_item"][$k]);
if(empty($_SESSION["cart_item"]))
unset($_SESSION["cart_item"]);
break;
// code for if cart is empty
case "empty":
unset($_SESSION["cart_item"]);
break;
if(isset($_POST['checkout'])){
$pid=$_SESSION['productid'];
$quantity=$_POST['quantity'];
$cname=$_POST['customername'];
$cmobileno=$_POST['mobileno'];
$pmode=$_POST['paymentmode'];
$value=array_combine($pid,$quantity);
$query=mysqli_query($con,"insert into
tblorders(ProductId,Quantity,InvoiceNumber,CustomerName,CustomerContactNo,PaymentMode)
values('$pdid','$qty','$invoiceno','$cname','$cmobileno','$pmode')") ;
unset($_SESSION["cart_item"]);
$_SESSION['invoice']=$invoiceno;
echo "<script>window.location.href='invoice.php'</script>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Search Product</title>
</head>
<body>
<?php include_once('includes/navbar.php');
include_once('includes/sidebar.php');
?>
<div id="hk_nav_backdrop" class="hk-nav-backdrop"></div>
<div class="hk-pg-wrapper">
</ol>
</nav>
<div class="container">
<div class="hk-pg-header">
</div>
<div class="row">
<div class="col-xl-12">
<section class="hk-sec-wrapper">
<div class="row">
<div class="col-sm">
<div class="form-row">
</div>
</div>
</form>
</div>
</div>
</section>
<section class="hk-sec-wrapper">
<div class="row">
<div class="col-sm">
<div class="table-wrap">
<thead>
<tr>
<th>#</th>
<th>Category</th>
<th>Company</th>
<th>Product</th>
<th>Pricing</th>
<th>Quantity</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$pname=$_POST['productname'];
$cnt=1;
while($row=mysqli_fetch_array($query))
{
?>
<tr>
<td>
</td>
</tr>
</form>
<?php
$cnt++;
} ?>
</tbody>
</table>
</div>
</div>
</div>
</section>
<?php } ?>
<section class="hk-sec-wrapper">
<div class="row">
<div class="col-sm">
<div class="table-wrap">
<h4>Shopping Cart</h4>
<hr />
<?php
if(isset($_SESSION["cart_item"])){
$total_quantity = 0;
$total_price = 0;
?>
<tbody>
<tr>
<th>Category</th>
<th>Company</th>
<th width="5%">Quantity</th>
<th width="10%">Price</th>
<th width="5%">Remove</th>
</tr>
<?php
$productid=array();
$item_price = $item["quantity"]*$item["price"];
array_push($productid,$item['code']);
?>
<tr>
</tr>
<?php
$total_quantity += $item["quantity"];
$total_price += ($item["price"]*$item["quantity"]);
$_SESSION['productid']=$productid;
?>
<tr>
<td></td>
</tr>
</tbody>
</table>
<div class="form-row">
</div>
</div>
<div class="form-row">
</div>
</div>
</div>
</div>
</div>
</form>
<?php
} else {
?>
<div style="color:red" align="center">Your Cart is Empty</div>
<?php
?>
</div>
</div></div></section>
</div>
</div>
</div>
<?php include_once('includes/footer.php');?>
</div>
</div>
<script src="vendors/jquery/dist/jquery.min.js"></script>
<script src="vendors/popper.js/dist/umd/popper.min.js"></script>
<script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="vendors/jasny-bootstrap/dist/js/jasny-bootstrap.min.js"></script>
<script src="dist/js/jquery.slimscroll.js"></script>
<script src="dist/js/dropdown-bootstrap-extended.js"></script>
<script src="dist/js/feather.min.js"></script>
<script src="vendors/jquery-toggles/toggles.min.js"></script>
<script src="dist/js/toggle-data.js"></script>
<script src="dist/js/init.js"></script>
<script src="dist/js/validation-data.js"></script>
<style type="text/css">
#btnEmpty {
background-color: #ffffff;
color: #d00000;
float: right;
text-decoration: none;
border-radius: 3px;
</style>
</body>
</html>
<?php } ?>
This is code
Fatal error: Uncaught TypeError: Unsupported operand types: string + array in C:\
xampp\htdocs\balajibakeryf\dfsms\search-product.php:26 Stack trace: #0 {main}
thrown in C:\xampp\htdocs\balajibakeryf\dfsms\search-product.php on line 26
This is error
Error
SQL query: Copy
--
-- Constraints for table `tblproducts`
--
ALTER TABLE `tblproducts`
ADD CONSTRAINT `catnamr` FOREIGN KEY (`CompanyName`) REFERENCES `tblcompany`
(`CompanyName`) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD CONSTRAINT `compname` FOREIGN KEY (`CompanyName`) REFERENCES `tblcategory`
(`CategoryName`) ON DELETE NO ACTION ON UPDATE NO ACTION;
MySQL said:
#1452 - Cannot add or update a child row: a foreign key constraint fails (`dfsms`.`#sql-18b4_10f`,
CONSTRAINT `compname` FOREIGN KEY (`CompanyName`) REFERENCES `tblcategory`
(`CategoryName`) ON DELETE NO ACTION ON UPDATE NO ACTION)