PHP code for cart.php - cart is always empty - php

I have these two codes for product.php and cart.php...
`Product.php:
<?php
session_start();
if (!isset($_SESSION['user'])) {
header('Location: login.php');
exit;
}
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
require 'db.inc.php';
if (!isset($_GET['id'])) {
header('Location: store.php');
exit;
}
$product = findProductById($_GET['id']);
$features = findProductFeaturesById($_GET['id']);
if (isset($_POST['submit'])) {
$id = $_POST['product_id'];
$quantity = $_POST['quantity'];
}
if (!$product) {
header('Location: store.php');
exit;
}
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Lab 3">
<meta name="author" content="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
</head>
<body class="">
<header class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center col-md-3 mb-2 mb-md-0 text-dark text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap">
<use xlink:href="#bootstrap"></use>
</svg>
</a>
<ul class="nav nav-pills col-12 col-md-auto mb-2 justify-content-center mb-md-0">
<li>Le catalogue</li>
<li>Mes achats</li>
</ul>
<div class="col-md-3 text-end me-1">
<a class="btn btn-outline-primary" href="logout.php" role="button">Quitter</a>
</div>
</header>
<main class="container">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Catalogue complet</li>
<li class="breadcrumb-item active" aria-current="page"><?= $product->short_name ?></li>
</ol>
</nav>
<div class="row">
<div class="card mb-3 pb-6 col-6" style="width: 36rem;">
<div class="card-body">
<div class="card-text">
<h1><?= $product->name ?></h1>
</div>
<div class="card-title display-2 text-end">
<?= $product->price ?>$
</div>
</div>
</div>
<div class="col-2">
</div>
<div class="col-4">
<p class="text-start h2 row"><?= $product->available_quantity ?> en stock</p>
</div>
</div>
<h2>A propos de cet article</h2>
<ul>
<?php
// Rajout des caractéristiques à partir de la fonction findProductFeaturesById //
$features = findProductFeaturesById($product->id);
foreach ($features as $feature) {
echo '<li>' . $feature['feature'] . '</li>';
}
?>
</ul>
<form action="cart.php" method="post">
<input type="hidden" name="product_id" value="<?=$product->id?>">
<label for="quantity">Quantité:</label>
<input type="number" name="quantity" value="1" min="1" max="<?=$product->available_quantity?>">
<input type="submit" value="Ajouter au panier">
<?php
if (isset($_POST['submit'])) {
$id = $_POST['product_id'];
$quantity = $_POST['quantity'];
addProductToCart($id, $quantity);
header('Location: cart.php');
exit;
}
?>
</form>
</main>
</body>
</html>
cart.php:
<?php
session_start();
if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
}
require 'db.inc.php';
if (isset($_POST['submit'])) {
$product_id = $_POST['product_id'];
$quantity = $_POST['quantity'];
if (!isset($_SESSION['cart'][$product_id])) {
$_SESSION['cart'][$product_id] = array(
'product_id' => $product_id,
'quantity' => $quantity
);
} else {
$_SESSION['cart'][$product_id]['quantity'] += $quantity;
}
}
if (isset($_POST['update'])) {
$product_id = $_POST['product_id'];
$quantity = $_POST['quantity'];
if (!isset($_SESSION['cart'][$product_id])) {
$_SESSION['cart'][$product_id] = array(
'product_id' => $product_id,
'quantity' => $quantity
);
} else {
$_SESSION['cart'][$product_id]['quantity'] = $quantity;
}
}
foreach ($_SESSION['cart'] as $item) {
$product = findProductById($item['product_id']);
$product->quantity = $item['quantity'];
$products[] = $product;
}
$cart = $_SESSION['cart'];
function addProductToCart($id, $quantity)
{
if (isset($_SESSION['cart'][$id])) {
$_SESSION['cart'][$id]['quantity'] += $quantity;
} else {
$_SESSION['cart'][$id] = array(
'product_id' => $id,
'quantity' => $quantity
);
}
}
// lorsque la quantité est 0, le produit est retiré du panier
function updateProductQuantity($id, $quantity)
{
if ($quantity == 0) {
unset($_SESSION['cart'][$id]);
} else {
$_SESSION['cart'][$id]['quantity'] = $quantity;
}
}
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Lab 4">
<meta name="author" content="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
</head>
<body class="">
<header class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center col-md-3 mb-2 mb-md-0 text-dark text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap">
<use xlink:href="#bootstrap"></use>
</svg>
</a>
<ul class="nav nav-pills col-12 col-md-auto mb-2 justify-content-center mb-md-0">
<li>Le catalogue</li>
<li>Vos achats</li>
<li>Vos commandes</li>
</ul>
<div class="col-md-3 text-end me-1">
<a class="btn btn-outline-primary" href="logout.php" role="button">Quitter</a>
</div>
</header>
<main class="container">
<h1>Votre panier</h1>
<?php if (count($_SESSION['cart']) != 0) :?>
<div class="list-group mb-3">
<?php foreach ($cart as $id => $quantity) :
$product = findProductById($id);
?>
<div class="list-group-item">
<form method="POST" id="update_cart_form" action="cart.php">
<input type="hidden" name="id" value="<?= $id ?>">
<h2><?= $product->short_name ?></h2>
<label for="quantity" class="row">Quantité :</label>
<input type="number" class="plaintext row" id="quantity" name="quantity" value="<?= $quantity ?>">
<button type="submit" class="btn btn-link row">Mettre à jour</button>
<button type="submit" class="btn btn-link row">Supprimer</button>
</form>
</div>
<?php endforeach; ?>
</div>
<form method="POST" id="pay_cart_form" action="orders.php">
<button type="submit" class="btn btn-primary" name="action" value="pay_cart">Payer maintenant</button>
</form>
<?php else :?>
<p>Votre panier est vide!</p>
<?php endif;?>
</main>
</body>
</html>`
I tried to change the code many times, but at the end the cart array is always empty... i dont understand why?
I tried to change the code to make sure i POST quantity and id to display the right product with quantity, but the cart stays empty.

It looks like PHP is not persisting your session even though it is being created, which will always return the initial value as the default value.
First, you must check if the cookie is being created on the browser. Open the developer inspection tool, go to Cookie Storage and see if there is a session cookie, by default its name is PHPSESSID.
If a cookie is not being created, you must check session.save_path configuration in your php.ini file. Your PHP must not have the permissions for writing and creating sessions.
However, if a cookie is being created, run the code below on your host:
<?php
session_start();
if (!isset($_SESSION['counter'])) {
$_SESSION['counter'] = 0;
}
$_SESSION['counter']++;
echo 'Counter: '.$_SESSION['counter'];
If the counter is not incremented, the PHP creates a session but it's not saving it. You must check if there are any errors related to sessions in the error logs, pointing to an invalid configuration or misspelled configuration.
At this point, if the counter is working but your $_SESSION['cart'] is not being updated, try to do the following:
Make sure session_start() is running on top of your code three, before any other code ran;
Make sure that the same session ID is used when refreshing pages, and changing pages;
Try to isolate the problem by breaking your code and executing it step by step on browser.
EDIT 1
Sometimes when redirecting to another location with the header() method, the session data can be not saved before the header is sent. The natural fix is constructing a better code. Try to use the session_write_close() method before sending the new header.

Related

Hide and show button based on user SESSION in php foreach loop

Im trying to not show the remove button to the users that did not uploaded image to website, and I want the remove button be shown only for the user that uploaded a specific image.
The problem is, it is in foreach loop, I tried with
if($user_id == $_GET['id']
but it show every button, but when I put
if($user_id != $_GET['id'])
all button disappear.
This is the button I would like to show/hide
<?php
require('dbconfig.php');
if(!$user->is_loggedIn()) {
$user->Redirect('index.php');
}
$user_id = $_SESSION['user_session'];
$stmt = $db_conn->prepare("SELECT * FROM users WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
// print_r($userRow);
if(isset($_POST['ok'])) {
$folder = "/Library/WebServer/Documents/Website/uploads/";
$image = $_FILES['image']['name'];
$path = $folder . $image ;
$target_file=$folder.basename($_FILES["image"]["name"]);
$imageFileType=pathinfo($target_file,PATHINFO_EXTENSION);
$allowed=array('jpeg','png' ,'jpg'); $filename=$_FILES['image']['name'];
$ext=pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed)) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
} else {
$success = "Image uploaded successfully";
move_uploaded_file( $_FILES['image'] ['tmp_name'], $path);
$stmt = $db_conn->prepare("INSERT INTO images (img, user_id) VALUES (:image, :user_id)");
$stmt->bindparam(":image",$image);
$stmt->bindparam(":user_id",$user_id);
$stmt->execute();
}
}
$subjects = $db_conn->prepare("SELECT img FROM images");
$subjects->setFetchMode(PDO::FETCH_ASSOC);
$subjects->execute();
$stmt = $db_conn->prepare("SELECT user_id FROM images");
$stmt->execute();
$nesto=$stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<pre>';
print_r($nesto);
echo '</pre>';
// echo $nesto['user_id'];
$ids = $_GET['id'];
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Jekyll v4.0.1">
<title>Management</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<!-- Custom styles for this template -->
<link href="album.css" rel="stylesheet">
</head>
<body>
<header>
<div class="navbar navbar-dark bg-dark shadow-sm">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true" class="mr-2" viewBox="0 0 24 24" focusable="false"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>
<strong>Pictures</strong>
</a>
Home
Profile
</div>
</div>
</header>
<main role="main">
<section class="jumbotron text-center">
<div class="container">
<h1>Shared Gallery</h1>
<p class="lead text-muted"><?php print($userRow['user_name']); ?></p>
<p>
<p><?php echo $success; ?></p>
<!-- Upload Image Form -->
<div>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" name="ok"/>
</form>
</div>
<!-- End Upload Image Form -->
Logout
</p>
</div>
</section>
<div class="album py-5 bg-light">
<div class="container">
<div class="row">
<!-- START -->
<?php foreach($subjects as $subject) { ?>
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<img src="uploads/<?php echo $subject['img']; ?>" class="bd-placeholder-img card-img-top" width="100%" height="225" focusable="false"/>
<div class="card-body">
<p class="card-text">
<ul>
<li>Username</li>
<li>Email</li>
<li>Address</li>
</ul>
</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
THIS IS THE BUTTON I WANT TO SHOW AND HIDE
<button type="button" class="btn btn-sm btn-outline-secondary">Remove</button>
THIS IS THE BUTTON I WANT TO SHOW AND HIDE
</div>
<small class="text-muted">9 mins</small>
</div>
</div>
</div>
</div>
<?php } ?>
<!-- END -->
</div>
</div>
</div>
</main>
<footer class="text-muted">
<div class="container">
<p class="float-right">
Back to top
Back to index
</p>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="/docs/4.5/assets/js/vendor/jquery.slim.min.js"><\/script>')</script><script src="/docs/4.5/dist/js/bootstrap.bundle.min.js" integrity="sha384-1CmrxMRARb6aLqgBO7yyAxTOQE2AKb9GfXnEo760AUcUmFx3ibVJJAzGytlQcNXd" crossorigin="anonymous"></script>
</body></html>
If you change these 2 queries into one query, you would have a resultset with the img and the users id, you can then use that to compare with the user that is logged in
//$subjects = $db_conn->prepare("SELECT img FROM images");
//$subjects->setFetchMode(PDO::FETCH_ASSOC);
//$subjects->execute();
//$stmt = $db_conn->prepare("SELECT user_id FROM images");
//$stmt->execute();
//$nesto=$stmt->fetchAll(PDO::FETCH_ASSOC);
Replace as
$result = $db_conn->query("SELECT img, user_id FROM images");
$subjects = $result->fetchAll(PDO::FETCH_ASSOC);
Then around your button you can do
<?php
// If this user uploaded this image they are allowed to remove it
if ($subject->user_id == $_SESSION['user_session']) :
<button type="button" class="btn btn-sm btn-outline-secondary">Remove</button>
endif;
?>
Big Note
I dont see a session_start() in this code, as you are using $_SESSION you would need one of those right at the top of this script.
I decided to do it this way
This worked for me perfectly.
<!-- START -->
<?php foreach($subjects as $subject) : ?>
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<img src="uploads/<?php echo $subject['img']; ?>" class="bd-placeholder-img card-img-top" width="100%" height="225" focusable="false"/>
<div class="card-body">
<p class="card-text">
<ul>
<li><?php echo $subject['img_id']; ?></li>
<li><?php echo $subject['user_name']; ?></li>
<li><?php echo $subject['user_email']; ?></li>
<li>Address</li>
</ul>
</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<?php foreach($subject as $val) : ?>
<?php if ($user_id == $_SESSION['user_session'] && $val == $user_id) : ?>
<?php $id = $subject['img_id']; ?>
<form method="POST" action="<?php echo "delete.php?id=" . $subject['img_id']?>">
<!-- <button name="remove" type="button" class="btn btn-sm btn-outline-secondary">Remove</button> -->
<input type="hidden" name="del" value="1" />
<input type="submit" name="del" class="btn btn-sm btn-outline-secondary" value="Remove" />
</form>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<!-- END -->

How to use INNER JOIN to display data edited by different users

I need to create a record in my database that when a user edits the description field it would save it to the database (this currently works). But when the user wants to add another note to the same note added earlier it just saves over the old note. (am using UPDATE for that).
So I would like to know how to achieve this? In my code below you will see that I have two text areas, 1 to display the record from the database and the other to add a new note to the database. Ideally I would to like to display each new note in a new unedited-able text area (sort of like displaying the history of all notes added to the original note.
<?php
require_once '../config.php';
$description_err = "";
if(isset($_POST["id"]) && !empty($_POST["id"])){
$id = $_POST["id"];
$input_description = trim($_POST["descriptionfield"]);
if(empty($input_description)){
$description_err = "Please enter a description.";
} else{
$description= $input_description;
}
if(empty($description_err)){
$sql = "UPDATE newtask SET new_description=? WHERE id=?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "si", $param_description, $param_id);
$param_description = $description;
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
header("location: user-dashboard.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($link);
} else{
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
$id = trim($_GET["id"]);
$sql = "SELECT * FROM newtask WHERE id = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$description = $row["new_description"];
} else{
header("location: ../error.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
} else{
header("location: ../error.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-
scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Support Admin</title>
<link href="../assets/css/bootstrap.css" rel="stylesheet" />
<link href="../assets/css/font-awesome.min.css" rel="stylesheet" />
<link href="../assets/css/style.css" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Nova+Flat"
rel="stylesheet" type="text/css" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700,300"
rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="head">
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<a href="../index.php">
<img src="../assets/img/logo1.png" />
</a>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text-center" >
<img src="../assets/img/top-mouse.png " class="header-mid"
/>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h4><span>Call:</span> 082 </h4>
<h4><span>E-mail:</span> sales</h4>
</div>
</div>
</div>
</div>
<section>
<div class="container">
<div class="row noti-div">
<div class="col-lg-3 col-md-3 col-sm-3 text-center">
</div>
</div>
</div>
</section>
<section id="main">
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-9 col-sm-9 alert alert-info">
<h3 class=" text-center">Update Task</h3>
<div class="hr-div"> <hr />
</div>
<form action="<?php echo
htmlspecialchars(basename($_SERVER['REQUEST_URI']));
?>" method="post">
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?
php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>New Note<textarea name="descriptionfield"
class="formcontrol</textarea>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<label>Note Added By </label>
<textarea class="form-control"><?php echo $description; ?></textarea>
</div>
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<a href="index.php" class=" label label-danger">
<strong>LOGOUT</strong> </a>
<div class="list-group">
<a href="#" class="list-group-item active">Quick Links
</a>
My Dashboard
Open Tasks
Pending Tasks
Completed Tasks
Change Password
</div>
<div class="alert alert-success text-center">
<h3>The Notice Board</h3>
No Notice Found !
</div>
<div class="list-group">
Support Categories
Notes
Manuals
General Information
</div>
</div>
</div>
</div>
</section>
<div id="footer">
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<h3>This</h3>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h3>Contact Details</h3>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery-1.10.2.js"></script>
<script src="assets/js/bootstrap.js"></script>
</body>
</html>
So as you can see in the above code its updating my "newtask" table which I would assume that it needs to update the new table called "updatedata" (this is not in the code above as I am not sure how to add it as well as the id of the two tables)
It then displays the data from the "newtask" table (Original table).
How would I go about to achieve this as per my question above?
Thanks guys
EDIT
So as from the below image I want to have the text from "updatedata" table to link to id 1 from "newtask" table. And then display that text in different div in my page.
I would like to link all the new texts from update data to newtask without over writing the data already in newtask.
So I would to display like the below

Storing order details in MYSQL database using php

I'm trying to learn php and MYSQL through developing an eCommerce website. So far the experience with these new languages are really good, but I'm stuck on one of my ideas. I have managed to add the order details to my database, however it adds only a product at a time. Originally what I wanted to do is to add more than a product and store it in a database.
For an example let's say an user wants to buy 5 items. How can I store this into my database. With my current code this just add as a single product with the total of 5 products.(Even the quantity is not adding up).
I'm not sure whether my code is correct. Any suggestions on this is really appreciated. (Please feel free to modify code, it will be really helpful)
Following is the code I'm using to add orders to database.
<div class="col-md-12">
<h4 class="text-center">Paypal Intergration Goes Here.</h4>
<img src="./images/paywith_paypal.png" class="img-responsive center-block" alt="Pay With Paypal">
<?php
// Getting product details
$total = 0;
global $con;
$ip = getIp();
$sel_price = "SELECT * FROM zeus_limited.cart WHERE ip_address='$ip'";
$run_price = mysqli_query($con, $sel_price);
while($p_price=mysqli_fetch_array($run_price)){
$product_id = $p_price['cart_product_id'];
$product_price = "SELECT * FROM zeus_limited.product WHERE product_id='$product_id'";
$run_product_price = mysqli_query($con,$product_price);
while ($prod_price = mysqli_fetch_array($run_product_price)){
$product_price = array($prod_price['product_price']);
$product_id = $prod_price['product_id'];
$pro_name = $prod_price['product_title'];
$values = array_sum($product_price);
$total +=$values;
}
}
// Getting Quantity from cart
$get_quantity = "SELECT * FROM zeus_limited.cart WHERE cart_product_id='$product_id'";
$show_quantity = mysqli_query($con, $get_quantity);
$row_qty = mysqli_fetch_array($show_quantity);
$quantity = $row_qty['quantity'];
if($quantity == 0){
$quantity = 1;
}
else {
$quantity = $quantity;
$total = $total * $quantity;
}
// Getting Customer details
$user = $_SESSION['customer_email'];
$get_customer = "SELECT * FROM zeus_limited.customer WHERE customer_email='$user'";
$show_customer = mysqli_query($con, $get_customer);
$row_c = mysqli_fetch_array($show_customer);
$customer_id = $row_c['customer_id'];
$customer_email = $row_c['customer_email'];
$customer_name = $row_c['customer_fname'];
$trx_id = mt_rand();
$currency = 'USD';
$invoice = mt_rand();
// Insert data to ORDER table
$add_order = "INSERT INTO zeus_limited.orders (order_product_id, order_customer_id, order_quantity, invoice_no, status, order_date) VALUES ('$product_id','$customer_id','$quantity','$invoice','in Progress',NOW())";
$run_order = mysqli_query($con, $add_order);
// Insert data to PAYMENT table
$add_payment = "INSERT INTO zeus_limited.payment (amount, payment_customer_id, payment_product_id, trx_id, payment_currency, payment_date) VALUES ('$total','$customer_id','$product_id','$trx_id','$currency',NOW())";
$run_payment = mysqli_query($con, $add_payment);
// Removing products from CART
$empty_cart = "DELETE FROM zeus_limited.cart";
$show_customerart = mysqli_query($con, $empty_cart);
if($total == $total){
echo "<div class='text-center'>";
echo "<h3>Welcome:" . $_SESSION['customer_email']. "<br>" . "Hooray! Your Payment was successful!</h3>";
echo "<a href='./customer/my_account.php'>Go to your Account</a><br>";
echo "</div>";
}
else {
echo "<div class='text-center'>";
echo "<h4>Welcome Guest, Payment process failed... Please try again</h4><br>";
echo "<a href='/shop_products.php'>Go to Back to shop</a>";
echo "</div>";
}
?>
</div>
I'm attaching the cart code as well.(if it's needed)
<?php
session_start();
require_once './includes/init.php';
require_once './functions/functions.php';
echo getCart();
?>
<!DOCTYPE html>
<html>
<head>
<title>Zeus Pvt. Ltd</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<link rel="stylesheet" href="css/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
<script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="header">
<div class="container container-bg">
<div class="row">
<div class="col-md-4"><img src="images/logo.png" class="img-responsive" alt="Responsive image"></div>
<div class="col-md-5"></div>
<div class="col-md-3">
<div class="zeus_cart">
<div class="cart_bg">
<ul class="cart">
<i class="cart_icon"></i><p class="cart_desc"><?php getTotalCartPrice() ?><br><span class="yellow"><?php getTotalItems() ?></span></p>
<div class='clearfix'></div>
</ul>
<ul class="product_control_buttons">
<li><img src="images/close.png" alt=""/></li>
<li>Edit</li>
</ul>
<div class='clearfix'></div>
</div>
<ul class="quick_access">
<li class="view_cart">View Cart</li>
<li class="check">Checkout</li>
<div class='clearfix'></div>
</ul>
</div>
</div>
</div>
</div>
<div class="container container-bg">
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">Shop Products</li>
<li>My Account</li>
<li>Contact Us</li>
<li>
<?php
if(!isset($_SESSION['customer_email'])){
echo 'Login';
}
else {
echo 'Logout';
}
?>
</li>
<li class="welcome"><a>Welcome <?php echo getUsername(); ?></a></li>
</ul>
<form method="get" action="results.php" enctype="multipart/form-data" class="navbar-form navbar-right">
<div class="form-group search">
<input type="text" name="user_query" class="form-control" placeholder="Search Products">
</div>
<button type="submit" class="btn btn-default btn-search"></button>
</form>
</div>
</div>
</div>
</nav>
</div>
<div class="main">
<div class="container container-bg">
<div class="row">
<div class="col-md-12">
<div class="shoppingcart-title">
<h4 class="text-center sidebar-main-menu">Shopping Cart</h4>
<div class="table-responsive">
<form action="" method="POST" enctype="multipart/form-data">
<table class="table">
<thead>
<tr>
<th>Product No.</th>
<th>Product(s)</th>
<th>Name</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Sub Total</th>
<th>Remove</th>
</tr>
</thead>
</tbody>
<?php
global $con;
$total = 0;
$ip = getIp();
$select_price = "SELECT * FROM zeus_limited.cart WHERE zeus_limited.cart.ip_address='$ip'";
$run_price = mysqli_query($con, $select_price);
while ($product_price = mysqli_fetch_array($run_price)) {
$product_id = $product_price['cart_product_id'];
$product_quantity = $product_price['quantity'];
$product_price = "SELECT * FROM zeus_limited.product WHERE zeus_limited.product.product_id ='$product_id'";
$run_product_price = mysqli_query($con, $product_price);
while ($product_new_price = mysqli_fetch_array($run_product_price)) {
$product_price = array($product_new_price['product_price']);
$product_id = $product_new_price['product_id'];
$product_image = $product_new_price['product_image_carousel'];
$product_title = $product_new_price['product_title'];
$unit_product_price = $product_new_price['product_price'];
$values = array_sum($product_price);
$total += $values * $product_quantity;
?>
<tr>
<td><?php echo $product_id; ?></td>
<td><img src="images/products/<?php echo $product_image; ?>" </td>
<td><?php echo $product_title; ?></td>
<td><input id="" type="text" name="quantity[<?php echo $product_id; ?>]" size="5" value="<?php echo $product_quantity; ?>" style="text-align:center;"/>
<input type="hidden" name="product_id[<?php echo $product_id; ?>]" value="<?php echo $product_id; ?>"
</td>
<!--Updating the quantity-->
<?php
$ip = getIp();
if (isset($_POST['update_cart'])){
foreach ($_POST['product_id'] as $pid => $id) {
$product_id = $id;
$product_quantity = $_POST['quantity'][$pid];
$update_products = "UPDATE zeus_limited.cart SET quantity = '$product_quantity' WHERE cart_product_id = '$product_id' AND ip_address = '$ip';";
$run_update = mysqli_query($con, $update_products);
}
if($update_products){
echo "<script>window.open('cart.php','_self')</script>";
}
}
?>
<td><?php echo 'Rs '. $unit_product_price; ?></td>
<td><?php echo 'Rs '.$unit_product_price * $product_quantity ?></td>
<td><input type="checkbox" name="remove[]" value="<?php echo $product_id; ?>"/></td>
</tr>
</tbody>
<?php } } ?>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th>Grand Total: </th>
<th><?php echo 'Rs '. $total ?></th>
<th></th>
</tr>
</thead>
</table>
<div class="cart_buttons">
<input type="submit" name="update_cart" value="Update Cart"/>
<input type="submit" name="continue_shopping" value="Continue Shopping"/>
<input type="submit" name="checkout" value="Checkout"/>
<?php if (isset($_POST['checkout'])){echo "<script>window.open('checkout.php','_self')</script>"; } ?>
</div>
</form>
<?php
global $con;
$ip = getIp();
if (isset($_POST['update_cart'])){
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "DELETE FROM zeus_limited.cart WHERE cart_product_id='$remove_id' AND ip_address='$ip'";
$run_delete = mysqli_query($con, $delete_product);
if($run_delete){
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
if (isset($_POST['continue_shopping'])){
echo "<script>window.open('shop_products.php','_self')</script>";
}
?>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<div class="row">
<div class="col-md-4 footer-grid">
<h3>Menu</h3>
<ul class="list1">
<li>Home</li>
<li>Shop Products</li>
<li>My Account</li>
<li>Contact Us</li>
<li>Login</li>
</ul>
</div>
<div class="col-md-4 footer-grid">
<h3>Your Account</h3>
<ul class="list1">
<li>My Orders</li>
<li>Edit Account</li>
<li>Change Password</li>
<li>Delete Account</li>
<li>My Cart</li>
</ul>
</div>
<div class="col-md-4 footer-grid">
<h3>About Us</h3>
<p class="footer_desc">Zeus is a pharmacy focused on providing patients with what they need and deserve - exceptional pharmacy care. It is our responsibility and passion to care for your medication needs.</p>
<p class="f_text"><span class="fa fa-phone" aria-hidden="true"></span> Phone: +081 123 45 67</p>
<p class="email"><span class="fa fa-envelope" aria-hidden="true"></span> Email: <span>info#zeuspharmacy.com</span></p>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
</div>
<div class="footer-bottom">
<div class="container">
<div class="row">
<div class="col-md-12 footer-grid-bottom">
<div class="copyrights">
<p>© 2017 Zeus Pharmacy. Made with <span class="fa fa-heart" aria-hidden="true"></span> by Dilum Tharaka</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
order table structure image
payment table structure image
Above are the table structures I'm using. Thanks in advance

update database field based on what the user selects via dropdown

so on my site, the admin can assign a job to a user and that job will automatically have the status: waiting to be accepted. I have now created a drop down box on the job page so that the user can either decline or accept the job with that drop down box. however im unsure of the coding needed to update the database field based on what the user selects.
what im aiming for is: the user selects a status, then clicks the change button to update the status of the job.
current code:
<?php
if(!isset($_SESSION))
{
session_start();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<title>Tyre Hire</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css"/>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<header>
<img class="img-responsive" src ="images/Logo.png" alt ="logo"/>
</header>
</div>
</div>
<?php
require_once ("config.inc.php");
try
{
$conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
}
catch(PDOException $exception)
{
echo "Oh no, there was a problem" . $exception->getMessage();
}
if(!isset($_SESSION["username"]))
{
//user tried to access the page without logging in
header( "Location: add.php" );
}
$login = $_SESSION['user_ID'];
$query = "SELECT * FROM login WHERE user_ID = :user_ID";
$term = $conn->prepare($query);
$term->bindValue(':user_ID', $login);
$term->execute();
$login = $term->fetch(PDO::FETCH_OBJ);
$status = "Waiting to be accepted";
$status2 = "Accept Job";
$status3 = "Decline Job";
if(isset($_SESSION["username"]))
{
echo "Welcome, you are now logged in as <b>".$_SESSION['username']."</b> <img class='clientView' src='images/loginIcon.png' alt='client'>"; }
else {
echo "You are currently not logged in";
};
?>
<div class="row">
<div class="col-xs-12">
<br>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="main.php">Tyre Hire</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li> Home <span class="glyphicon glyphicon-print"></span></li>
<li> Search <span class="glyphicon glyphicon-print"></span></li>
<li><?php echo "<a href='all-jobs.php?user_id=" . $login->user_ID . "&occupation=". $login->occupation ."''> Current Jobs <span class='glyphicon glyphicon-print'></span></a>";?> </li>
<li> Register Interest <span class="glyphicon glyphicon-print"></span></li>
<li> Logout <span class="glyphicon glyphicon-print"></span></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="right">
<h2>Current Jobs</h2>
<p>One of the best sites to find the best qualified and skilled drivers in the UK.</p>
<form class="form-horizontal formApply" action="" method="POST">
<h2><u>Job Details </u></h2>
<div class="form-group">
<?php
echo "<h3>Job role :".$worker->jobTitle."</h3>";
echo "<ul>";
echo "<h3> About the role </h3>";
echo "<li><b>Company Name:</b>".$worker->company."</li>";
echo "<li><b>Job Description:</b>".$worker->jobDescription."</li>";
echo "<h3>shift pattern</h3>";
echo "<li><b>Start Time: </b>".$worker-> startTime."</li>";
echo "<li><b>End Time: </b>".$worker-> endTime."</li>";
echo "<br />";
echo "<li><b>start Date:</b>".$worker->startDate."</li>";
echo "<li><b>Job Expiry Date:</b>".$worker->expiry."</li>";
echo "<b><h4>Current Status: </b>".$worker->status."</h4>";
echo "</ul>";
?>
<div class="form-group">
<label class="control-label col-sm-2" for="search"> Status</label>
<div class="col-sm-3">
<select class="form-control" name="status" >
<option value="<? echo $status;?>"><?php echo $status;?></option>
<option value="<? echo $status2;?>"><?php echo $status2;?></option>
<option value="<? echo $status3;?>"><?php echo $status3;?></option>
</select>
<input type="hidden" value="<?php echo $status; ?>" name="status">
</div>
<div class="form-group">
<!--<label class="control-label col-sm-2" for="search"></label> -->
<div class="col-sm-3">
<!-- <select class="form-control" name="status" >
<option value="<? echo $job;?>"><?php echo $job;?></option>
</select> -->
<input type="hidden" value="<?php echo $job; ?>" name="job_id">
</div>
</div>
</div>
<input class = "buttonA" type="submit" name="Apply" value="Change status"/>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div id="BottomArea">
<h4> Recruitment Agencies </h4>
<div class="row">
<div class="col-xs-3">
<img class="FxPic img-responsive" src="images/fxpic.png" alt="fx-logo">
</div>
<div class="col-xs-3">
<img class="driverhire img-responsive" src="images/driverhire.jpg" alt="driverhire">
</div>
<div class="col-xs-3">
<img class="logi img-responsive" src="images/logi.png" alt="logi-logo">
</div>
<div class="col-xs-3">
<img class="pebble img-responsive" src="images/noel.png" alt="pebbles">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<footer>
<img id="logoFoot" src ="images/Logo.png" alt ="logo"/>
<p><b>Address: 5A twickenham road, london SJ5 7AE</b></p>
</footer>
</div>
</div>
<script src=myjs.js></script>
</div>
</body>
</html>
attempted it after reading the update manual, no errors but upon clicking the button it gives a blank page.:
<?php
include ("db_fncs.php");
try{
$conn = new PDO(DB_DATA_SOURCE, DB_USERNAME, DB_PASSWORD);
}
catch (PDOException $exception)
{
echo "Oh no, there was a problem" . $exception->getMessage();
}
$status = $_POST["status"];
$job = $_POST['job_id'];
print_r($_POST);
$query = "UPDATE jobs SET status = :status WHERE job_id = :job_id AND status = :status";
// Prepare statement
$stmt = $conn->prepare($query);
$stmt->bindValue(':status', $status);
$stmt->bindValue(':job_id', $job);
// execute the query
$stmt->execute();
//$stmt->commit();
echo $stmt->rowCount() . " records UPDATED successfully";
?>
The basic syntax for UPDATE is:
UPDATE <my_table>
SET <update_column_name> = <some_value>
WHERE <identifying_column_name> = <some_value>
In your case, it would probably look something like:
UPDATE jobs
SET status = <new_job_status>
WHERE userid = <user_id>
AND jobid = <job_id>

php sessions on different pages

I am new to php.I am developing a website and have some problems with sessions on different pages.When i login to website my header becomes
Main Reklam Logout Anna
And this is what happens when i click to other links in my website
Main Reklam Login Register
But when i click again to main the sessions are again there
Main Reklam Logout Anna
Here is my header.php
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Telefonal</title>
<meta name="description" content="Source code generated using layoutit.com">
<meta name="author" content="LayoutIt!">
<base href="http://domain.com"></base>
<link rel="stylesheet" href="<?php echo $config['template'];? >assets/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo $config['template'];?>assets/css/style.css">
<link rel="stylesheet" href="<?php echo $config['template'];?>assets/css/custom.css">
<link rel="stylesheet" href="<?php echo $config['template'];?>assets/css/font-awesome.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<link href='https://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="container-fluid" >
<!-- Navigation menu -->
<div class="row" >
<div class="col-md-12">
<nav class="navbar navbar-default top-navigation" role="navigation" >
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse " id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li id="left-first-list">
Main
</li>
<li id="left-second-list">
<img src="upload/main/website-design-symbol.png"> Reklam
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if(isset($_SESSION['user']) ){?>
<li id="right-first-list">
<img src="upload/main/login.png"> Logout
</li> <?php
}else{?>
<li id="right-first-list">
<img src="upload/main/login.png"> Login
</li>
<?php
}?>
<?php if(isset($_SESSION['user'])){?>
<li id="right-second-list">
<img src="upload/main/clipboard-with-pencil.png"> <?php echo $_SESSION['user'];?>
</li> <?php
}else{?>
<li id="right-second-list">
<img src="upload/main/clipboard-with-pencil.png"> Qeydiyyat
</li>
<?php }?>
</ul>
</div>
</nav>
</div>
</div>
And here is my login.php i am using facebook login
<?php
session_start();
//require 'functions.php';
// added in v4.0.0
require_once 'dbconfig.php';
require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication( '**********','*************8' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://www.domain.com/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['user_id'] = $fbid;
$_SESSION['user'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
// checkuser($fuid,$ffname,$femail);
$query="SELECT * from Users where Fuid='$fbid'";
$check = $db->query($query);
$res = $check->num_rows;
if (empty($res) || $res==0) { // if new user . Insert a new record
$query2 = "INSERT INTO Users VALUES ('". $fbid ."','$fbfullname','$femail')";
$db->query($query2);
$query_up="UPDATE Users SET Fuid='$fbid'";
$db->query($query_up);
$path="upload/".$fbid."/";
if (!file_exists($path)) {
mkdir($path);}
} else { // If Returned user . update the user record
$query3 = "UPDATE Users SET Ffname='$fbfullname', Femail='$femail' where Fuid='$fbid'";
$db->query($query3);
}
header("Location: index.php");
} else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
?>
Detail.php
<?php
if(isset($_GET['pid'])){
$pid=(int)$_GET['pid'];
$_SESSION['pid']=$pid;
$product_query=
"SELECT * from `ad`,`ad_description`
WHERE `ad`.`ad_id`=`ad_description`.`ad_id`
AND `ad`.`ad_id`='$pid'
AND `ad`.`created_date`< NOW()
ORDER BY `ad`.`created_date`
Limit 1";
$get_products_row=$db->query($product_query);
if($get_products_row->num_rows>0){
while($single_product=$get_products_row->fetch_assoc()){
$products[]=array(
'ad_id'=>$single_product['ad_id'],
'ad_name' =>$single_product['ad_name'],
'picture'=>$single_product['picture'],
'price'=>$single_product['price'],
'ad_description'=>$single_product['ad_description'],
'created_date'=>$single_product['created_date'],
'user_id'=>$single_product['user_id'],
'barter'=>$single_product['barter'],
'city'=>$single_product['city'],
'phone'=>$single_product['phone'],
);
}
//}
}else{
echo "lllllll";
//header("Location: index.php?page=404");
}
}else{
echo "aaaaaaa";
//header("Location: index.php?page=404");
}
require_once($config['template']."detail.php");
?>
<?php
include_once($config['template']."header.php");
include_once($config['template']."brand_list.php");
?>
<?php if(isset($products)){ ?>
<?php foreach ($products as $product) {
$image=$product['picture'];
$image_arr=explode("|*|", $image);
if (strlen($image_arr[1])!=0) {
$src1="upload/".$product['user_id']."/".$image_arr[1];
}else{
$src1="upload/main/no_image.gif";
}
if (strlen($image_arr[2])!=0) {
$src2="upload/".$product['user_id']."/".$image_arr[2];
}else{
$src2="upload/main/no_image.gif";
}
if (strlen($image_arr[3])!=0) {
$src3="upload/".$product['user_id']."/".$image_arr[3];
}else{
$src3="upload/main/no_image.gif";
}
if (strlen($image_arr[4])!=0) {
$src4="upload/".$product['user_id']."/".$image_arr[4];
}else{
$src4="upload/main/no_image.gif";
}
if ($product['picture']==1) {
$barter="mümkündür";
}else{
$barter="mümkün deyil";
}
$url=$_SERVER['REQUEST_URI'];
$check_url="SELECT * from counter where page_url='$url'";
$row=$db->query($check_url);
if ($row->num_rows == 0) {
$query="INSERT INTO counter values(NULL,'$url','1')";
$db->query($query);
}else{
$query2="UPDATE counter
SET count=count+1
WHERE page_url='$url'";
$db->query($query2);
}
$query_select_hits="SELECT count from counter where page_url='$url'";
$row_for_hit=$db->query($query_select_hits);
while ($data=$row_for_hit->fetch_assoc()) {
$hits=$data['count'];
}
//$hits=$row_for_hit->num_rows;
?>
<div class="row">
<div class="col-md-12">
<div class="row" >
<div class="col-md-6" >
<div class="row" >
<div class="col-md-12">
<table class="table" >
<thead>
<tr>
<!-- <th>
#
</th> -->
<th>
<?php echo $product['ad_name']; ?>
</th>
<!-- <th>
Payment Taken
</th>
<th>
Status
</th> -->
</tr>
</thead>
<tbody>
<tr>
<td>
Model
</td>
<td>
<?php echo $product['ad_name']; ?>
</td>
</tr>
<tr class="active">
<td>
Barter imkani
</td>
<td>
<?php echo $barter;?>
</td>
</tr>
<tr >
<td>
Şəhər
</td>
<td>
<?php echo $product['city'];?>
</td>
</tr>
<tr class="active">
<td>
Dərc olunma tarixi
</td>
<td>
<?php echo $product['created_date'];?>
</td>
</tr>
<tr >
<td>
Qiymət
</td>
<td>
<?php echo $product['price'];?> AZN
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12 elave-melumat">
<h3>
Baxilib <img style="width:40px;height:40px;border-radius:10px;" src="upload/main/animated.gif" /> <?php echo $hits;?>
</h3>
<div>
<p>
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 elave-melumat">
<h3>
Əlavə məlumat
</h3>
<div>
<p>
<?php echo $product['ad_description'];?>
</p>
</div>
</div>
</div>
<div class="row" >
<div class="col-md-12 elaqe">
<h3>
Əlaqə
</h3>
<div>
<p>
<?php echo $product['phone'];?>
</p>
</div>
</div>
</div>
<div class="row" >
<div class="col-md-12 elaqe">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6&appId=234614743547307";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-comments" data-href="https://www.facebook.com/telefonalaz-1013127532086903/" data-width="500" data-numposts="3">
</div>
</div>
</div>
</div>
<div class="col-md-6 allImages" >
<div class="row" >
<div class="col-md-6 detail-picture">
<img id="myImg" alt="Trolltunga, Norway" width="270" height="200" src="<?php echo $src1; ?>"/>
<!-- The Modal -->
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
<img id="myImg" alt="Trolltunga, Norway" width="270" height="200" src="<?php echo $src2; ?>"/>
<!-- The Modal -->
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
</div>
<div class="col-md-6 detail-picture">
<img id="myImg" alt="Trolltunga, Norway" width="270" height="200" src="<?php echo $src3; ?>"/>
<!-- The Modal -->
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
<img id="myImg" alt="Trolltunga, Norway" width="270" height="200" src="<?php echo $src4;?>" />
<!-- The Modal -->
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
</div>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
modalImg.alt = this.alt;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
</script>
</div>
</div>
</div>
<?php } }?>
<!-- end of detail part -->
<?php
include_once($config['template']."footer.php");
?>
EDIT:
my website is http://telefonal.az/
In other page (as OP has mentioned) please make sure you have session_start(); function before you are using $_SESSION.
for example
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
/*session is started if you don't write this line can't use $_Session global variable*/
}
echo $_SESSION['user_id'];

Categories