У меня проблемы с получением данных для отправки в cart_chekout

У меня проблема с получением данных для отправки или перехода на следующую страницу. Я подозреваю, что это время цикла. пытаюсь ввести несколько данных Я пытаюсь ввести несколько элементов в базу данных с информацией о пользователях, но я не знаю, как это сделать. Я знаю, что код не велик и может получить инъекции sql, я работаю над переписыванием всего кода.

cart.php

<?php

session_start();
if(!isset($_SESSION["uid"])){
header("location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Supplies</title>
<link rel="stylesheet" href="http://a0319p528/project2/assets/css/bootstrap.css"/>
<script src="http://a0319p528/project2/assets/js/jquery2.js"></script>
<script src="http://a0319p528/project2/assets/js/bootstrap.min.js"></script>
<script src="http://a0319p528/project2/main.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapse" aria-expanded="false">
<span class="sr-only">navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand"> Supplies</a>
</div>
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav">
<li><a href="index.php"><span class="glyphicon glyphicon-home"></span>Home</a></li>
<li><a href="index.php"><span class="glyphicon glyphicon-modal-window"></span>Product</a></li>
</ul>
</div>
</div>
</div>
<p><br/></p>
<p><br/></p>
<p><br/></p>
<div class="container-fluid">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8" id="cart_msg">
<!--Cart Message-->
</div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="panel panel-primary">
<div class="panel-heading">Cart Checkout</div>
<div class="panel-body">
<div class="row">
<div class="col-md-2 col-xs-2"><b>Action</b></div>
<div class="col-md-2 col-xs-2"><b>Product Image</b></div>
<div class="col-md-2 col-xs-2"><b>Product Name</b></div>
<div class="col-md-2 col-xs-2"><b>Quantity</b></div>
<div class="col-md-2 col-xs-2"><b>Product Price</b></div>
<div class="col-md-2 col-xs-2"><b>Price in $</b></div>
</div>
<div id="cart_checkout"></div>
<!--<div class="row">
<div class="col-md-2">
<div class="btn-group">
<a href="#" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
<a href="" class="btn btn-primary"><span class="glyphicon glyphicon-ok-sign"></span></a>
</div>
</div>
<div class="col-md-2"><img src='product_images/imges.jpg'></div>
<div class="col-md-2">Product Name</div>
<div class="col-md-2"><input type='text' class='form-control' value='1' ></div>
<div class="col-md-2"><input type='text' class='form-control' value='5000' disabled></div>
<div class="col-md-2"><input type='text' class='form-control' value='5000' disabled></div>
</div> -->
<!--<div class="row">
<div class="col-md-8"></div>
<div class="col-md-4">
<b>Total $500000</b>
</div> -->
</div>
</div>
<div class="panel-footer"></div>
</div>
</div>
<div class="col-md-2"></div>

</div>
</body>
</html>

action.php

    <script src="assets/js/textboxname_autocomplete.js" type="text/javascript"></script>

<?php
session_start();
include "db.php";
if(isset($_POST["category"])){
$category_query = "SELECT * FROM categories";
$run_query = mysqli_query($con,$category_query) or die(mysqli_error($con));
echo "<div class='nav nav-pills nav-stacked'>
<li class='active'><a href='#'><h4>Categories</h4></a></li>
";
if(mysqli_num_rows($run_query) > 0){
while($row = mysqli_fetch_array($run_query)){
$cid = $row["cat_id"];
$cat_name = $row["cat_title"];
echo "<li><a href='#' class='category' cid='$cid'>$cat_name</a></li>
";
}
echo "</div>";
}
}
if(isset($_POST["vendor"])){
$vendor_query = "SELECT * FROM vendors";
$run_query = mysqli_query($con,$vendor_query);
echo "<div class='nav nav-pills nav-stacked'>
<li class='active'><a href='#'><h4>Vendors</h4></a></li>
";
if(mysqli_num_rows($run_query) > 0){
while($row = mysqli_fetch_array($run_query)){
$vid = $row["vendor_id"];
$vendor_name = $row["vendor_title"];
echo "<li><a href='#' class='selectVendor' vid='$vid'>$vendor_name</a></li>
";
}
echo "</div>";
}
}
if(isset($_POST["page"])){
$sql = "SELECT * FROM products";
$run_query = mysqli_query($con,$sql);
$count = mysqli_num_rows($run_query);
$pageno = ceil($count/9);
for($i=1;$i<=$pageno;$i++){
echo "<li><a href='#' page='$i' id='page'>$i</a></li>
";
}
}

if(isset($_POST["getProduct"])){

$product_query = "SELECT * FROM products Order by product_title";
$run_query = Mysqli_query($con, $product_query);
if(mysqli_num_rows($run_query) >0 ){
while($row = mysqli_fetch_array($run_query)){
$pro_id = $row['product_id'];
$pro_cat = $row['product_cat'];
$pro_vendor = $row['product_vendor'];
$pro_title = $row['product_title'];
$pro_price = $row['product_price'];
$pro_image = $row['product_image'];
$pro_desc = $row['product_desc'];
$pro_item_number = $row['product_item_number'];

echo "<div class='col-md-4 '>
<div class='panel panel-info'>
<div class='panel-heading'>$pro_title</div>
<div class='panel-body'>
<img src='assets/product_images/$pro_image' style ='width:100px; height:100px;'>
<p>$pro_desc</p>
<p>Item # $pro_item_number</p></div>
<div class='panel-heading'>$.$pro_price.00
<button pid='$pro_id' style='float:right;' id='product' class='btn btn-danger btn-xs'>AddToCart</button>
</div>
</div>
</div>";

}
}

}
if(isset($_POST["get_seleted_Category"]) || isset($_POST["selectVendor"]) || isset($_POST["search"])){
if(isset($_POST["get_seleted_Category"])){
$id = $_POST["cat_id"];
$sql = "SELECT * FROM products WHERE product_cat = '$id'";
}else if(isset($_POST["selectVendor"])){
$id = $_POST["vendor_id"];
$sql = "SELECT * FROM products WHERE product_vendor = '$id'";
}else {
$keyword = $_POST["keyword"];
$sql = "SELECT * FROM products WHERE product_keywords LIKE '%$keyword%'";
}

$run_query = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($run_query)){
$pro_id    = $row['product_id'];
$pro_cat   = $row['product_cat'];
$pro_vendor = $row['product_vendor'];
$pro_title = $row['product_title'];
$pro_price = $row['product_price'];
$pro_image = $row['product_image'];
$pro_item_number = $row['product_item_number'];

echo "<div class='col-md-4 box1'>
<div class='panel panel-info'>
div class='panel-heading'>$pro_title</div>

<div class='panel-body'>
<img src='assets/product_images/$pro_image' style ='width:100px; height:100px;'>
<p>$pro_desc</p>
<p>Item # $pro_item_number</p></div>

<div class='panel-heading'>$.$pro_price.00
<button pid='$pro_id' style='float:right;' id='product' class='btn btn-danger btn-xs'>AddToCart</button>
</div>
</div>
</div>
";
}
}

if(isset($_POST["addToProduct"])){

if(isset($_SESSION["uid"])){
$p_id = $_POST["proId"];
$user_id = $_SESSION["uid"];
$sql = "SELECT * FROM cart WHERE p_id = '$p_id' AND user_id = '$user_id'";
$run_query = mysqli_query($con,$sql);
$count = mysqli_num_rows($run_query);
if($count > 0){
echo "<div class='alert alert-warning'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<b>Product is already added into the cart Continue Shopping..!</b>
</div>
";//not in video
} else {
$sql = "SELECT * FROM products WHERE product_id = '$p_id'";
$run_query = mysqli_query($con,$sql);
$row = mysqli_fetch_array($run_query);
$id = $row["product_id"];
$pro_name = $row["product_title"];
$pro_image = $row["product_image"];
$pro_price = $row["product_price"];
$sql = "INSERT INTO `cart`
(`id`, `p_id`, `ip_add`, `user_id`, `product_title`,
`product_image`, `qty`, `price`, `total_amt`)
VALUES (NULL, '$p_id', '0', '$user_id', '$pro_name',
'$pro_image', '1', '$pro_price', '$pro_price')";
if(mysqli_query($con,$sql)){
echo "<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<b>Product is Added..!</b>
</div>
";
}
}
}else{
echo "<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<b>Sorry..!go and Sign Up First then you can add a product to your cart</b>
</div>
";
}}
//the issue starts here for the question I am asking.
if(isset($_POST["get_cart_product"]) || isset($_POST["cart_checkout"])){
$uid = $_SESSION["uid"];
$sql = "SELECT * FROM cart WHERE user_id = '$uid'";
$run_query = mysqli_query($con,$sql);
$count = mysqli_num_rows($run_query);
if($count > 0){
$no = 1;
$total_amt = 0;
while($row=mysqli_fetch_array($run_query)){
$id = $row["id"];
$pro_id = $row["p_id"];
$pro_name = $row["product_title"];
$pro_image = $row["product_image"];
$qty = $row["qty"];
$pro_price = $row["price"];
$total = $row["total_amt"];
$price_array = array($total);
$total_sum = array_sum($price_array);
$total_amt = $total_amt + $total_sum;
setcookie("ta",$total_amt,strtotime("+1 day"),"/","","",TRUE);
if(isset($_POST["get_cart_product"])){
echo "<div class='row'>
<div class='col-md-3 col-xs-3'>$no</div>
<div class='col-md-3 col-xs-3'><img src='assets/product_images/$pro_image' width='60px' height='50px'></div>
<div class='col-md-3 col-xs-3'>$pro_name</div>
<div class='col-md-3 col-xs-3'>$.$pro_price.00</div>
</div>
";
$no = $no + 1;
}else{
echo "<div class='row'>
<div class='col-md-2 col-sm-2'>
<div class='btn-group'>
<a href='#' remove_id='$pro_id' class='btn btn-danger btn-xs remove'><span class='glyphicon glyphicon-trash'></span></a>
<a href='' update_id='$pro_id' class='btn btn-primary btn-xs update'><span class='glyphicon glyphicon-ok-sign'></span></a>
</div>
</div>";echo"
<form action='user_information.php' id='form1' method='post'>
<div class='col-md-2 col-sm-2'><img src='assets/product_images/$pro_image' width='50px' height='60'></div>
<div class='col-md-2 col-sm-2'><input name='name' type='text' class='form-control qty' pid='$pro_name ' id='qty-$pro_name ' value='$pro_name ' ></div>
<div class='col-md-2 col-sm-2'><input name='qty' type='text' class='form-control qty' pid='$pro_id' id='qty-$pro_id' value='$qty' ></div>
<div class='col-md-2 col-sm-2'><input name='price' type='text' class='form-control price' pid='$pro_id' id='price-$pro_id' value='$pro_price' disabled></div>
<div class='col-md-2 col-sm-2'><input name ='total' type='text' class='form-control total' pid='$pro_id' id='total-$pro_id' value='$total' disabled></div>
</div>";
}
}echo"
<h3>Employee Information</h3>
<label>Lan ID</label>
<input type='text' name='lanId' id='lanId'  autocomplete='off'  class='form-control' >
<label>Employee Name</label>
<input type='text' name='employeeName' id='name'   autocomplete='off'  class='form-control'>
<label>Department</label>
<select name='department' id='department'  class='form-control'>
<option value =''>Select Department...</option>
<option value ='OTHER'> OTHER</option>

</select>

<label>Cost Center</label>
<input type='text' class='form-control' name='costCenter' value=''>
<br><br><br>
<input type='submit' class='btn btn-primary' value='Submit'>

</form>";if(isset($_POST["cart_checkout"])){
echo "<div class='row'>
<div class='col-md-8'></div>
<div class='col-md-4'>
<h1>Total $$total_amt</h1>
</div>";
}
echo '<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">';

$x=0;
$uid = $_SESSION["uid"];
$sql = "SELECT * FROM cart WHERE user_id = '$uid'";
$run_query = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($run_query)){
$x++;
echo  '<input type="hidden" name="item_name_'.$x.'" value="'.$row["product_title"].'">
<input type="hidden" name="item_number_'.$x.'" value="'.$x.'">
<input type="hidden" name="amount_'.$x.'" value="'.$row["price"].'">
<input type="hidden" name="quantity_'.$x.'" value="'.$row["qty"].'">';}

}
}

if(isset($_POST["cart_count"]) AND isset($_SESSION["uid"])){
$uid = $_SESSION["uid"];
$sql = "SELECT * FROM cart WHERE user_id = '$uid'";
$run_query = mysqli_query($con,$sql);
echo mysqli_num_rows($run_query);
}
if(isset($_POST["removeFromCart"])){
$pid = $_POST["removeId"];
$uid = $_SESSION["uid"];
$sql = "DELETE FROM cart WHERE user_id = '$uid' AND p_id = '$pid'";
$run_query = mysqli_query($con,$sql);
if($run_query){
echo "<div class='alert alert-danger'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<b>Product is Removed from Cart Continue Shopping..!</b>
</div>
";
}
}

if(isset($_POST["updateProduct"])){
$uid = $_SESSION["uid"];
$pid = $_POST["updateId"];
$qty = $_POST["qty"];
$price = $_POST["price"];
$total = $_POST["total"];

$sql = "UPDATE cart SET qty = '$qty',price='$price',total_amt='$total'
WHERE user_id = '$uid' AND p_id='$pid'";
$run_query = mysqli_query($con,$sql);
if($run_query){
echo "<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
<b>Product is Updated Continue Shopping..!</b>
</div>
";
}
}

?>

main.js

$(document).ready(function(){
cat();
vendor();
product();
function cat(){
$.ajax({
url :   "action.php",
method: "POST",
data    :   {category:1},
success :   function(data){
$("#get_category").html(data);

}
})
}
function vendor(){
$.ajax({
url :   "action.php",
method: "POST",
data    :   {vendor:1},
success :   function(data){
$("#get_vendor").html(data);
}
})
}
function product(){
$.ajax({
url :   "action.php",
method: "POST",
data    :   {getProduct:1},
success :   function(data){
$("#get_product").html(data);
}
})
}
$("body").delegate(".category","click",function(event){
$("#get_product").html("<h3>Loading...</h3>");
event.preventDefault();
var cid = $(this).attr('cid');

$.ajax({
url     :   "action.php",
method  :   "POST",
data    :   {get_seleted_Category:1,cat_id:cid},
success :   function(data){
$("#get_product").html(data);
if($("body").width() < 480){
$("body").scrollTop(683);
}
}
})

})
$("body").delegate(".selectVendor","click",function(event){
event.preventDefault();
$("#get_product").html("<h3>Loading...</h3>");
var vid = $(this).attr('vid');

$.ajax({
url     :   "action.php",
method  :   "POST",
data    :   {selectVendor:1,vendor_id:vid},
success :   function(data){
$("#get_product").html(data);
if($("body").width() < 480){
$("body").scrollTop(683);
}
}
})

})
$("#search_btn").click(function(){
$("#get_product").html("<h3>Loading...</h3>");
var keyword = $("#search").val();
if(keyword != ""){
$.ajax({
url     :   "action.php",
method  :   "POST",
data    :   {search:1,keyword:keyword},
success :   function(data){
$("#get_product").html(data);
if($("body").width() < 480){
$("body").scrollTop(683);
}
}
})
}
})
$("#signup_button").click(function(event){
event.preventDefault();
$.ajax({
url     :   "register.php",
method  :   "POST",
data    :   $("form").serialize(),
success :   function(data){
$("#signup_msg").html(data);
}
})

})
$("#login").click(function(event){
event.preventDefault();
var lanId = $("#lanId").val();
var pass = $("#password").val();
$.ajax({
url :   "login.php",
method: "POST",
data    :   {userLogin:1,userLanId:lanId,userPassword:pass},
success :function(data){
if(data == "truefsvkjbskvvsbd"){
window.location.href = "profile.php";
}
}
})
})
cart_count();
$("body").delegate("#product","click",function(event){
event.preventDefault();
var p_id = $(this).attr('pid');
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {addToProduct:1,proId:p_id},
success :   function(data){
$("#product_msg").html(data);
cart_count();
}
})
})
cart_container();
function cart_container(){
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {get_cart_product:1},
success :   function(data){
$("#cart_product").html(data);
}
})

};
function cart_count(){
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {cart_count:1},
success :   function(data){
$(".badge").html(data);
}
})
}

$("#cart_container").click(function(event){
event.preventDefault();
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {get_cart_product:1},
success :   function(data){
$("#cart_product").html(data);
}
})

})
cart_checkout();
function cart_checkout(){
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {cart_checkout:1},
success : function(data){
$("#cart_checkout").html(data);
}
})
}
$("body").delegate(".qty","keyup",function(){
var pid = $(this).attr("pid");
var qty = $("#qty-"+pid).val();
var price = $("#price-"+pid).val();
var total = qty * price;
$("#total-"+pid).val(total);
})
$("body").delegate(".remove","click",function(event){
event.preventDefault();
var pid = $(this).attr("remove_id");
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {removeFromCart:1,removeId:pid},
success :   function(data){
$("#cart_msg").html(data);
cart_checkout();
}
})
})
$("body").delegate(".update","click",function(event){
event.preventDefault();
var pid = $(this).attr("update_id");
var qty = $("#qty-"+pid).val();
var price = $("#price-"+pid).val();
var total = $("#total-"+pid).val();
$.ajax({
url :"action.php",
method  :   "POST",
data    :   {updateProduct:1,updateId:pid,qty:qty,price:price,total:total},
success :   function(data){
$("#cart_msg").html(data);
cart_checkout();
}
})
})
page();
function page(){
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {page:1},
success :   function(data){
$("#pageno").html(data);
}
})
}
$("body").delegate("#page","click",function(){
var pn = $(this).attr("page");
$.ajax({
url :   "action.php",
method  :   "POST",
data    :   {getProduct:1,setPage:1,pageNumber:pn},
success :   function(data){
$("#get_product").html(data);
}
})
})
})

-1

Решение

Вы определяете свой <form> внутри вашего elseтак что если ваш if правильно, форма никогда не будет работать.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector