2025-06-06 17:14:52 +08:00

34 lines
1.1 KiB
PHP

<?php
include "../../ConnectDB.php";
session_start();
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
$usertype = mysqli_real_escape_string($conn, $_SESSION['user_type']);
if(isset($_GET["name"])) {
$name = $_GET["name"];
//seller cannot add more than 100kg
if($usertype == "seller"){
$sql_check = "SELECT $name FROM seller WHERE name='$username'";
$res = mysqli_query($conn, $sql_check);
$num = mysqli_fetch_array($res);
if($num[$name] + 1 > 100){
echo "<script type='text/javascript'>
alert('You cannot sell more than 100kg/fruit one time!');
window.location.href = '../cart_index.php';
</script>";
exit();
}
}
$add = "UPDATE $usertype SET $name = $name + 1 WHERE name='$username'";
$res = mysqli_query($conn, $add);
if(!$res){
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
}
header('Location: ../cart_index.php');
?>