Initial commit
This commit is contained in:
58
indexes/process/addcart.php
Normal file
58
indexes/process/addcart.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
|
||||
session_start();
|
||||
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
||||
$usertype = mysqli_real_escape_string($conn, $_SESSION['user_type']);
|
||||
if($usertype == "seller"){
|
||||
$a = "seller_availability";
|
||||
}
|
||||
else{
|
||||
$a = "buyer_availability";
|
||||
}
|
||||
|
||||
if(isset($_GET["name"], $_GET["quantity"])) {
|
||||
$name = $_GET["name"];
|
||||
$quantity = $_GET["quantity"];
|
||||
|
||||
//if get null value
|
||||
if($quantity == ""){
|
||||
echo "<script type='text/javascript'>
|
||||
window.top.location.href = '../../home.php';
|
||||
</script>";
|
||||
return;
|
||||
}
|
||||
|
||||
$check_sql = "SELECT $a FROM inventory WHERE name = '$name'";
|
||||
$res = mysqli_query($conn, $check_sql);
|
||||
$avail = mysqli_fetch_array($res);
|
||||
|
||||
//if not available
|
||||
if($avail[$a] != 1){
|
||||
echo "<script type='text/javascript'>
|
||||
alert('This fruit is currently unavailable!');
|
||||
window.top.location.href = '../../home.php';
|
||||
</script>";
|
||||
return;
|
||||
}
|
||||
|
||||
$sql_quant = "SELECT $name FROM $usertype WHERE name='$username'";
|
||||
$res = mysqli_query($conn, $sql_quant);
|
||||
if ($res) {
|
||||
$num = mysqli_fetch_array($res);
|
||||
//if seller tries to sell more than 100kg fruits
|
||||
if(($usertype == "seller" && $num[$name] + $quantity <= 100) || $usertype == "buyer"){
|
||||
$add = "UPDATE $usertype SET $name = $name+$quantity WHERE name='$username'";
|
||||
$res = mysqli_query($conn, $add);
|
||||
}
|
||||
else{
|
||||
echo "<script type='text/javascript'>
|
||||
alert('You can only sell 100kg/type fruit one time!');
|
||||
window.top.location.href = '../../home.php';
|
||||
</script>";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: ./interfaces/success.php');
|
||||
?>
|
||||
Reference in New Issue
Block a user