function __construct($id = -1) { if (self::$conn == Null) { self::$conn = mysqli_connect('localhost', 'root', 'root', 'Commerce'); } if ($id != -1) { $query = "select * from shopp_cart where id={$id} limit 1"; $result = mysqli_query(self::$conn, $query); $pro = mysqli_fetch_assoc($result); $this->id = $pro['id']; $this->user_id = $pro['user_id']; $this->product_id = $pro['product_id']; $this->quantity = $pro['quantity']; $this->but_not = $pro['but_not']; } }
$response['data'] = array('user' => $user); $rest = new car_server(); $rest->handle_response($response['data'], 200); // $response['data']=array('user'=>$user); // $response['status'] = 'OK'; } else { $response['data'] = 'user not found'; $rest = new car_server(); $rest->handle_response($response['data'], 400); // $response['data'] = 'user not found'; // $response['status'] = 'Bad Request'; } // $json_response = json_encode($response); // echo $json_response; } elseif (isset($_GET['user_id'])) { $product = new shope(); $data = $product->count_product($_GET['user_id']); if (count($data) > 0) { $response['data'] = $data; $rest = new car_server(); $rest->handle_response($response['data'], 200); } } else { // get all users $user = new Users(); $data = $user->users(); if (count($data) > 0) { $response['data'] = $data; $rest = new car_server(); $rest->handle_response($response['data'], 200); // $response['status']='OK';
<?php session_start(); include 'classes/product.php'; include 'classes/categories.php'; include 'classes/users.php'; include 'classes/shope_car.php'; if (isset($_SESSION['user_id'])) { $user = new Users($_SESSION['user_id']); } $sum = 0; $obj_car = new shope(); $obj_product = new Product(); $data = $obj_car->product_car($_SESSION['user_id']); // print_r($data); foreach ($data as $key => $value) { // echo $value['id']; $obj_car->update_to_buy($value['id']); $sum += $value['quantity'] * $value['price']; $quantity = $value['total_quantity'] - $value['quantity']; $obj_product->update_quantity($value['id_pro'], $quantity); } $user->credit = $user->credit - $sum; $user->update_credit(); echo "<meta http-equiv='Refresh' content='0; url=home.php' />"; // header ("Location: home.php");
<?php session_start(); include 'classes/product.php'; include 'classes/categories.php'; include 'classes/users.php'; include 'classes/shope_car.php'; if (isset($_SESSION['user_id'])) { $user = new Users($_SESSION['user_id']); // echo "Hello, ".$user->name; // echo "<a href='logout.php'>Logout</a>"; print_r($user->name); print_r($user->credit); } $obj = new shope(); $data = $obj->product_car($_SESSION['user_id']); print_r($data); $sum = 0; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title>Cart | E-Shopper</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/font-awesome.min.css" rel="stylesheet"> <link href="css/prettyPhoto.css" rel="stylesheet">