function login() { global $db; $email = $_POST['email']; $password = $_POST['password']; $password = sha1(sha1($password) . sha1("mySalt@\$#(%")); $sql = "select * from user where email = '{$email}' and password = '******'"; $result = mysqli_query($db, $sql); if ($result->num_rows === 0) { return array("failure"); } else { $row = $result->fetch_array(); $_SESSION['user'] = $row['id']; $user_id = $row['id']; $query = "SELECT COUNT( id ) AS count FROM `cart` WHERE user_id = '{$user_id}';"; $result2 = $db->query($query); return array("success", $result2->fetch_assoc()['count'], get_elements_in_cart()); } }
<div id="cart-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h1 class="text-center">Added Items</h1> </div> <div class="modal-body"> <ul class="list-group"> <?php $result = get_elements_in_cart(); $numRows = $result->num_rows; if ($numRows > 0) { while ($cart = $result->fetch_assoc()) { include '_cart.php'; } } else { echo '<h3 class="form col-md-12 center-block text-decore" id="no-elements"> No elements in cart</h3>'; } ?> </ul> </div> <div class="modal-footer"> <div class="col-md-12"> <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> </div> </div> </div> </div> </div>