php sessions on different pages - php

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'];

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 have a mysql query print out in bootstrap cards alongside each other

I am trying to get a mysql query of results to print out alongside each other, say 3 in a row and not one below the other.
I have tried stack overlow answers and I cannot find one that helps
<?php
include('db.php');
$results = mysqli_query($conn, "SELECT * FROM contacts");
if(isset($_GET['edit'])){
$id = $_GET['edit'];
$edit_state = true;
$rec =mysqli_query($db_connection, "SELECT * FROM contacts WHERE id=$id ");
$record = mysqli_fetch_array($rec);
$name = $record['name'];
$contact = $record['contact'];
$email = $record['email'];
$id =
$record['id'];
}?>
<div class="container">
<h1 class="my-4">Welcome to Modern Business</h1>
<!-- Marketing Icons Section -->
<?php while ($row = mysqli_fetch_array($results)){ ?>
<div class="row">
<div class="col-lg-4 mb-4">
<div class="card h-100">
<h4 class="card-header"><?php echo $row['name']; ?></h4>
<img class="img_size" src="images/dog2.jpg" alt="Card image top">
<div class="card-body">
<p class="card-text"><?php echo $row['contact']; ?></p>
</div>
<div class="card-footer">
Learn More
</div>
</div>
</div>
</div>
<?php } ?>
right now, the cards are printing out but not inline, one below the other. I would like them to print horizontally.
any help at all would be appreciated, I am new to php.
This is the wrong outcome, I want them beside each other
PHP code:
<?php
include('dbconn.php'); // include database connection
$output="";
$selQuery = "select * from tbl_name";
$exeQuery = mysqli_query($conn,$selQuery);
$output="<h2>Welcome to Modern Business
<div class='container'>
<div class='row'>";
while($row = mysqli_fetch_array($exeQuery)) {
$name = $row['name'];
$desciption = $row['desciption'];
$ephoto = $row['ephoto'];
$output.="<div class='col-sm-4'>
<h4 class='card-header'>$name</h4>
<img class='img_size' src='$ephoto' alt='Card image top'>
<p>$desciption</p>
<a href='#' class='btn btn-primary'>Learn More</a>
</div>";
}
$output.="</div></div></h2>";
echo $output;
?>
HTML markup including bootstrap links:
<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
</html>
You need to put the while loop before the following div and end it when div ends.
<?php while($row=mysqli_fetch_array($results)){ ?>
<div class="card h-100">
<h4 class="card-header">
<?php echo $row['name']; ?></h4>
<img class="img_size" src="images/dog2.jpg" alt="Card image top">
<div class="card-body">
<p class="card-text"><?php echo $row['contact']; ?></p> </div>
<div class="card-footer">
<a href="#" class="btn btn-primary">
Learn More
</a>
</div>
</div>
<?php } ?>
Also replace col-lg-4 with col-lg-12
Try this and update me.

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>

Trying to make link with user id in joomla

I'm trying to add button with link to a seller store in my joomla component and I have no idea how can I do it.
I'm adding code from php file that has what I need but I don't know how to add it on another page. If someone can guide me with some how to step it would be awesome.
Here is the page that has the link to the store:
<?php
// no direct access
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
/** #var SellaciousViewProduct $this */
$sellers = $this->item->get('sellers');
if (!isset($sellers[0]) || (count($sellers) == 1 && $sellers[0]->seller_uid == $this->item->get('seller_uid')))
{
return;
}
$c_currency = $this->helper->currency->current('code_3');
?>
<div class="clearfix"></div>
<a name="also-selling"> </a>
<hr class="isolate"/>
<h4 class="center"><?php echo JText::_('COM_SELLACIOUS_PRODUCT_HEADING_BLOCK_SELLERS'); ?></h4>
<table class="product-sellers table table-striped table-hover table-bordered">
<thead>
<tr>
<th>SELLER </th>
<th>DELIVERY INFO</th>
<th>PRICE </th>
<th>ACTION </th>
</tr>
</thead>
<tbody>
<?php
foreach ($sellers as $i => $seller)
{
/** #var Registry $item */
$item = new Registry($seller);
$s_currency = $this->helper->currency->forSeller($item->get('seller_uid'), 'code_3');
// todo: Add this to config (show current one or not in more sellers) and move to model
if ($item->get('seller_uid') == $this->item->get('seller_uid'))
{
continue;
}
?>
<tr>
<td style="width: 220px;" class="nowrap">
<div class="seller-info">
<a href="<?php echo JRoute::_('index.php?option=com_sellacious&view=store&id=' . $item->get('seller_uid')); ?>">
<?php echo $item->get('seller_company', $item->get('seller_name')); ?></a>
<?php $rating = $item->get('seller_rating.rating'); ?>
<span class="label <?php echo ($rating < 3) ? 'label-warning' : 'label-success' ?>"><?php echo number_format($rating, 1) ?> / 5.0</span>
</div>
<?php if ($item->get('exchange_days')): ?>
<?php if ($item->get('exchange_tnc')):
$options = array(
'title' => '<strong>' . (int) $item->get('exchange_days') . ' Days</strong> Replacement Guarantee',
'backdrop' => 'static',
);
echo JHtml::_('bootstrap.renderModal', 'exchange_tnc-' . $item->get('code'), $options, $item->get('exchange_tnc'));
endif; ?>
<div class="replacement-info">
<i class="fa fa-refresh"></i>
<strong> <?php echo (int) $item->get('exchange_days') ?> Days</strong> Replacement
<?php if ($item->get('exchange_tnc')): ?>
[<i class="fa fa-question"></i>]
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($item->get('return_days')): ?>
<?php if ($item->get('return_tnc')):
$options = array(
'title' => '<strong>' . (int) $item->get('return_days') . ' Days</strong> Easy Return',
'backdrop' => 'static',
);
echo JHtml::_('bootstrap.renderModal', 'return_tnc-' . $item->get('code'), $options, $item->get('return_tnc'));
endif; ?>
<div class="replacement-info">
<i class="fa fa-refresh"></i>
<strong> <?php echo (int) $item->get('return_days') ?> Days</strong> Easy Return
<?php if ($item->get('return_tnc')): ?>
[<i class="fa fa-question"></i>]
<?php endif; ?>
</div>
<?php endif; ?>
<div>
<?php $allowed_listing_type = (array) $this->helper->config->get('allowed_listing_type'); ?>
<?php if (count($allowed_listing_type) != 1): ?>
<span class="label label-info margin-top-10">Condition:
<?php
$list_type = $item->get('listing_type');
// What if this is a not allowed listing type value
if ($list_type == 1):
echo JText::plural('COM_SELLACIOUS_PRODUCT_FIELD_LISTING_TYPE_VALUE', $list_type);
else:
$list_cond = $item->get('item_condition');
echo JText::plural('COM_SELLACIOUS_PRODUCT_FIELD_ITEM_CONDITION_VALUE', $list_type * 10 + (int) $list_cond);
endif;
?>
</span>
<?php endif; ?>
</div>
</td>
<td>
<div class="delivery-info">
<?php echo JHtml::_('date', '+ ' . rand(1, 30) . ' days', 'D, dS F'); ?>
<br>
<small><?php
$flat_ship = $item->get('flat_shipping');
$ship_fee = $item->get('shipping_flat_fee');
if ($flat_ship == 0)
{
echo JText::_('COM_SELLACIOUS_PRODUCT_SHIPPING_FEE_IN_CART');
}
elseif (round($ship_fee, 2) > 0)
{
$fee = $this->helper->currency->display($ship_fee, $s_currency, $c_currency, true);
echo JText::sprintf('COM_SELLACIOUS_PRODUCT_SHIPPING_FEE_FLAT', $fee);
}
else
{
echo JText::_('COM_SELLACIOUS_PRODUCT_SHIPPING_FEE_FREE');
}
?></small>
</div>
</td>
<td style="width:90px;" class="center">
<span class="product-price-sm"><?php
echo $this->helper->currency->display($item->get('price.sales_price'), $s_currency, $c_currency, true) ?></span>
</td>
<td style="width:100px;" class="nowrap">
<?php $link = JRoute::_('index.php?option=com_sellacious&view=product&p=' . $item->get('code')); ?>
<button class="btn btn-primary btn-cart-sm">DETAILS</button><br/>
<button type="button" class="btn btn-warning btn-cart-sm btn-add-cart" data-item="<?php echo $item->get('code') ?>">ДОБАВИ В КОЛИЧКАТА</button>
<!--<button type="button" class="btn btn-success btn-cart-sm btn-add-cart"
data-item="<?php /*echo $item->get('code') */?>" data-checkout="true">КУПИ СЕГА</button>-->
</td>
</tr>
<?php
}
?>
</tbody>
</table>
And this is the file I'm trying to import the part with the link to the sellers store
<?php
// no direct access.
defined('_JEXEC') or die;
jimport('sellacious.loader');
if (class_exists('SellaciousHelper'))
{
$helper = SellaciousHelper::getInstance();
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- favicon -->
<link rel="shortcut icon" href="templates/sellacious/images/favicon/favicon.ico" type="image/x-icon" />
<link rel="icon" href="templates/sellacious/images/favicon/favicon.ico" type="image/x-icon" />
<?php
$user = JFactory::getUser();
$doc = JFactory::getDocument();
$app = JFactory::getApplication();
$sitename = $app->get('sitename');
JHtml::_('script', 'media/com_sellacious/js/plugin/messagebox/jquery.messagebox.min.js', false, false);
JHtml::_('stylesheet', 'media/com_sellacious/js/plugin/messagebox/jquery.messagebox.css', null, false);
$doc->addStyleSheet('//fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,300,400,700');
$doc->addStyleSheet('templates/sellacious/css/bootstrap.min.css', 'text/css', 'screen');
$doc->addStyleSheet('templates/sellacious/css/font-awesome.min.css', 'text/css', 'screen');
$doc->addStyleSheet('templates/sellacious/css/joomla-icons.css', 'text/css', 'screen');
$doc->addStyleSheet('templates/sellacious/css/smartadmin-production.css', 'text/css', 'screen');
$doc->addStyleSheet('templates/sellacious/css/smartadmin-skins.css', 'text/css', 'screen');
$doc->addStyleSheet('templates/sellacious/css/custom-style.css', 'text/css', 'screen');
if ($this->direction == 'rtl')
{
$doc->addStyleSheet('templates/sellacious/css/smartadmin-rtl.css', 'text/css', 'screen');
}
JHtml::_('jquery.framework');
JHtml::_('bootstrap.tooltip');
$doc->addScript('templates/sellacious/js/libs/jquery-ui-1.10.3.min.js'); // jQuery UI full, not from joomla core's minimised one
$doc->addScript('templates/sellacious/js/plugin/fastclick/fastclick.js'); // FastClick: For mobile devices
$doc->addScript('templates/sellacious/js/plugin/jquery-touch/jquery.ui.touch-punch.min.js'); // JS TOUCH plugin for mobile drag-drop touch events
$doc->addScript('templates/sellacious/js/plugin/msie-fix/jquery.mb.browser.min.js'); // browser msie issue fix
$doc->addScript('templates/sellacious/js/bootstrap/bootstrap.min.js'); // Bootstrap JS
$doc->addScript('templates/sellacious/js/notification/SmartNotification.min.js'); // Custom notification
$doc->addScript('templates/sellacious/js/plugin/cookie/jquery.cookie.min.js'); // cookie
$doc->addScript('templates/sellacious/js/sellacious-core.js'); // Sellacious core functions to work template wide
$doc->addScript('templates/sellacious/js/sellacious-notifier.js'); // Sellacious notification per view page
?>
<script data-pace-options='{ "restartOnRequestAfter": true }' src="templates/sellacious/js/plugin/pace/pace.min.js"></script>
<jdoc:include type="head"/>
<!--[if IE 7]>
<h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>
<![endif]-->
</head>
<?php $collapse = $app->input->cookie->get('collapsedmenu'); ?>
<body class="fixed-page-footer <?php echo $app->input->get('hidemainmenu') || $collapse ? 'minified' : '' ?>"><!--
The possible classes: smart-style-3, minified, fixed-ribbon, fixed-header, fixed-width -->
<!-- HEADER -->
<header id="header" class="btn-group-justified">
<div id="logo-group">
<?php
$logo = 'templates/sellacious/images/logo.png';
if (isset($helper) && $helper->access->isSubscribed()):
$altLogo = $helper->media->getImage('config.backoffice_logo', 1, false);
$logo = $altLogo ?: $logo;
endif;
?>
<span id="logo"><a class="pull-left" href="<?php echo JRoute::_('index.php') ?>">
<img src="<?php echo $logo ?>" alt="<?php echo htmlspecialchars($sitename) ?>"></a></span>
<?php if ($this->countModules('logo-group')) { ?>
<!-- OPTIMAL PLACE FOR NOTIFICATION MODULE -->
<jdoc:include type="modules" name="logo-group" style="none"/>
<?php } ?>
</div>
<?php if ($this->countModules('header-left')) { ?>
<!-- Project Context -->
<jdoc:include type="modules" name="header-left" style="none"/>
<?php } ?>
<!-- pulled right: nav area -->
<div class="pull-right" style="margin-right: 1px;">
<!-- logout button -->
<div id="logout" class="btn-header transparent pull-right cursor-pointer">
<?php $logout_url = 'index.php?option=com_login&task=logout&' . JSession::getFormToken() . '=1'; ?>
<span> <a href="<?php echo $logout_url ?>" title="Sign Out" data-action="userLogout" class="hasTooltip" data-placement="bottom"
data-logout-msg="You can improve your security further after logging out by closing this opened browser"><i
class="fa fa-sign-out"></i></a> </span>
</div>
<!-- end logout button -->
<!-- fullscreen button -->
<div id="fullscreen" class="btn-header transparent pull-right">
<span> <a href="javascript:void(0);" data-action="launchFullscreen" class="hasTooltip" data-placement="bottom"
title="Full Screen"><i class="fa fa-arrows-alt"></i></a> </span>
</div>
<!-- end fullscreen button -->
<!-- back to Joomla administrator button -->
<div id="my-tore" class="btn-header transparent pull-right cursor-pointer">
<span> <a href="../<?php echo basename(JPATH_ADMINISTRATOR); ?>/index.php" class="hasTooltip" data-placement="bottom"
title="Back to Joomla Administrator"><i class="fa fa-joomla"></i></a> </span>
</div>
<!-- end back to Joomla administrator button -->
<!-- Go to Joomla frontend button -->
<div id="joomla" class="btn-header transparent pull-right cursor-pointer">
<span> <a href="../index.php" target="_blank" class="hasTooltip" data-placement="bottom"
title="View Site"><i class="fa fa-external-link"></i></a> </span>
</div>
<!-- end Go to Joomla frontend button -->
<!-- Go to Joomla frontend button -->
<div id="hide-menu" class="btn-header transparent pull-right cursor-pointer">
<span> <a href="#" class="hasTooltip" data-placement="bottom" data-menu="hidemenu"
title="Menu"><i class="fa fa-reorder"></i></a> </span>
</div>
<!-- end Go to Joomla frontend button -->
<!-- Sync media button -->
<div id="sync-media" class="btn-header transparent pull-right cursor-pointer">
<span> <a href="javascript:void(0)" class="hasTooltip" data-placement="bottom" data-action="sync-media" style="width: 135px;"
title="Refresh Media Uploads"><i class="fa fa-refresh"></i> <span class="text-normal"> <?php
echo JText::_('COM_SELLACIOUS_MEDIA_SYNC_BUTTON_LABEL') ?> </span></a> </span>
</div>
<!-- end Sync media button -->
<?php if ($this->countModules('header-right')): ?>
<jdoc:include type="modules" name="header-right" style="none"/>
<?php endif; ?>
</div>
<!-- end pulled right: nav area -->
<?php if (isset($helper) && ($helper->access->check('config.edit') || !$helper->access->isSubscribed())): ?>
<div id="context-news" class="pull-right padding-5"><!-- dynamic news --></div>
<?php endif; ?>
</header>
<!-- END HEADER -->
<!-- Left panel : Navigation area -->
<?php if ($this->countModules('left-panel') || $this->countModules('menu')) { ?>
<!-- Note: This width of the aside area can be adjusted through LESS variables -->
<aside id="left-panel">
<div class="login-info">
<span> <!-- User image size is adjusted inside CSS, it should stay as it -->
<a style="cursor:auto;" id="show-shortcut" data-action="toggleShortcut" href="index.php?option=com_sellacious&view=profile">
<!--<img src="templates/sellacious/images/avatars/male.png" alt="me" class="online"/>-->
<i class="fa fa-user"></i>
<span><?php echo $user->get('name'); ?></span>
</a>
</span>
</div>
<!-- User info -->
<?php if ($this->countModules('left-panel')) { ?>
<jdoc:include type="modules" name="left-panel" style="none"/>
<?php } ?>
<!-- end user info -->
<!-- NAVIGATION : This navigation is also responsive
To make this navigation dynamic please make sure to link the node
(the reference to the nav > ul) after page load. Or the navigation will not initialize.
-->
<!-- User info -->
<?php if ($this->countModules('menu')) { ?>
<jdoc:include type="modules" name="menu" style="none"/>
<?php } ?>
<!-- end user info -->
<span class="minifyme"> <i class="fa fa-arrow-circle-left hit"></i> </span>
</aside>
<!-- END NAVIGATION -->
<?php } ?>
<!-- End Left panel : Navigation area -->
<!-- MAIN PANEL -->
<div id="main" role="main">
<!-- RIBBON -->
<div id="ribbon">
<!-- breadcrumb -->
<?php if ($this->countModules('ribbon-left')) { ?>
<jdoc:include type="modules" name="ribbon-left" style="none"/>
<?php } ?>
<!-- end breadcrumb -->
<?php if ($this->countModules('ribbon-right')) { ?>
<span class="ribbon-button-alignment pull-right">
<jdoc:include type="modules" name="ribbon-right" style="none"/>
</span>
<?php } ?>
<div class="btn-headactions pull-right">
<i class="fa fa-book"></i> Documentation
<i class="fa fa-phone"></i> Support
<i class="fa fa-star"></i> Rate us on JED
</div>
</div>
<!-- END RIBBON -->
<?php if ($this->countModules('toolbar') || $this->countModules('title')) : ?>
<div class="box-toolbar">
<div class="">
<!-- col -->
<div class="pull-left">
<!-- PAGE HEADER -->
<jdoc:include type="modules" name="title"/>
</div>
<!-- end col -->
<!-- right side of the page with the sparkline graphs -->
<!-- col -->
<div class="pull-right">
<?php if ($this->countModules('toolbar')) : ?>
<span class="pull-right">
<jdoc:include type="modules" name="toolbar" style="none"/>
</span>
<?php endif; ?>
</div>
<!-- end col -->
</div>
</div>
<?php endif; ?>
<?php if ($this->countModules('top')) : ?>
<div class="row">
<div class="col-sm-12">
<jdoc:include type="modules" name="content-top" style="xhtml"/>
</div>
</div>
<?php endif; ?>
<?php if ($this->countModules('submenu')) : ?>
<div class="row">
<div class="col-sm-12">
<jdoc:include type="modules" name="submenu" style="none"/>
</div>
</div>
<?php endif; ?>
<div class="clearfix"></div>
<!-- MAIN CONTENT -->
<div id="content">
<?php if ($this->countModules('content-top')) { ?>
<div class="row">
<jdoc:include type="modules" name="content-top" style="none"/>
</div>
<?php } ?>
<div class="clearfix"></div>
<div class="component content-wrap">
<div id="system-message-container"><jdoc:include type="message" style="xhtml"/></div>
<div class="clearfix"></div>
<jdoc:include type="component" style="xhtml"/>
<div class="clearfix"></div>
</div>
<?php if ($this->countModules('content-bottom')) { ?>
<div class="row">
<jdoc:include type="modules" name="content-bottom" style="none"/>
</div>
<?php } ?>
</div>
<div class="clearfix"></div>
<!-- END MAIN CONTENT -->
</div>
<!-- END MAIN PANEL -->
<?php if ($this->countModules('footer')) { ?>
<jdoc:include type="modules" name="footer" style="none"/>
<?php } ?>
<jdoc:include type="modules" name="dynamic" style="xhtml"/>
<!-- Google Analytics code below -->
<?php if ($ga_code = $this->params->get('ga_code')) { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo htmlspecialchars($ga_code) ?>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
<?php } ?>
</body>
</html>
I understand that I need this link,
<a href="<?php echo JRoute::_('index.php?option=com_sellacious&view=store&id=' . $item->get('seller_uid')); ?>">
<?php echo $item->get('seller_company', $item->get('seller_name')); ?></a>
but don't know how to implement it in the second file.
You need access to the view object from the sellacious product view in your file (i.e. the this in $sellers = **$this**->item->get('sellers')). Your file is a template file, and templates don't have access to the component view object - it's already been marked for garbage collection by the time the template renders. If you are only rendering the sellacious store links on pages that include the sellacious component, you could copy and store the data in JRegistry to use in the template. You could do this in a layout override from your template (layouts have access to their component's view object). If it's for use in your custom component or other components, you'd need to write model logic to pull the information from the database. In that case, I'd look at how the sellacious model is doing it and copy just the parts you need.

Create loop which redirects to another page after condition is met

I'm trying to create a loop, which redirects to another script when the condition is met. But at the moment, it meets the condition, ends the loop, but doesn't redirect to the script. Nothing I have done works...
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('INCLUDE_CHECK',true);
require '../config/connection.php';
session_name('ppRemember');
session_set_cookie_params(86400);
session_start();
//get value from database. if is pending then display loading else display summary. if is complete but no session set say session has expired
if (isset($_SESSION['txnId'])) {
if ($_SESSION['txnId']==true) {
header('Location: ../confirmation');
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="basket-empty" title="Success" style="display:none;">
<p>Basket emptied</p>
</div>
<div id="confirm-empty" title="Confirm" style="display:none;">
<p>Are you sure you want to empty your basket?</p>
</div>
<div id="page-wrapper">
<div id="page">
<div id="header" class="without-secondary-menu">
<div class="section clearfix">
<div id="logo-caption">
<a href="/" title="Home" rel="home" id="logo">
</a>
</div>
<div id="caption">
</div>
<div id="main-menu" class="navigation">
<ul id="main-menu-links" class="links clearfix">
<li class="menu-2 active-trail active"> Order Online </li>
<li class="menu-9"> My Account </li>
<?php if (!$_SESSION['id']) {?>
<li class="menu-10"> Sign In </li>
<?php } ?>
<li class="menu-5"> Get a Quote </li>
<li class="menu-6"> Contact Us </li>
<li class="menu-11"> News </li>
<li class="menu-8"> Uploads </li>
<li class="menu-7"> Downloads </li>
</ul>
</div>
</div>
</div>
<?php if (isset($_SESSION['id'])) { ?>
<div id="panel" class="clearfix">
<div id="account-links">
<ul class="username">
<li><span class="account-links">You are logged in as <b><?php echo $_SESSION['username']; ?></b></span>
<span class="logout">Logout</span></li>
</ul>
</div>
</div>
<?php } ?>
<div id="main-wrapper" class="clearfix">
<div id="main" class="clearfix">
<div class="content">
<a id="main-content"></a>
<div class="tabs">
</div>
<div class="region region-content">
<div id="block-system-main" class="block block-system">
<div class="content">
<div id="node-1" class="clearfix">
<div class="content clearfix">
<?php if (!isset($_SESSION['txnId'])) {
if (isset($_SESSION['cart'])) { ?>
<div class="loading2" style="height:300px;">
<span class="text2"><font size="6pt"><b>Loading....</b></font></span>
<img src="../images/ajax-loader2.gif"/><br />
<font size="3pt"><b>Please wait a moment whilst we process your payment</b></font><br />
<font size="1pt"><b>Click here to reload after 10 seconds</b></font>
</div>
<?php }
} ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer-wrapper">
<div class="section">
<div id="footer" class="clearfix">
<div class="region region-footer">
<div class="block">
<div class="content">
<div class="column1">
</div>
<div class="column2">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
$trans = $_SESSION['transaction_id'];
$clientId = $_SESSION['id'];
if (!isset($_SESSION['txnId'])){
while ($_SESSION['txnId']!=true) {
$mysqli = new mysqli("localhost", "#####", "#####", "######");
$stmt = $mysqli->prepare("SELECT `txn_id` FROM `trans` AS t, `order_table` AS ot, `customer_order_details` AS cod WHERE t.transaction_id=?
&& t.transaction_id = ot.transaction_id && ot.customer_order_details_id = cod.customer_order_details_id && cod.client_id=?");
$stmt->bind_param('ii',$trans,$clientId);
if ($stmt->execute()) {
$stmt->store_result();
$num_rows = $stmt->num_rows;
if ($num_rows>=1) {
$stmt->bind_result($txnidrow);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
$_SESSION['CARRYTXNID'] = $txnidrow;
$_SESSION['txnId'] = true;
}
}
}
}
header('Location: ../confirmation');
die();
}
?>
Any headway is greatly appreciated. I've tried a do while loop, header without die/exit. I've removed all code and redirected the page on it's own, ran the script and all is fine. Etc, etc. I echo'd something to make sure that the condition is finally met, as well.
Following your edit, the solution here is actually quite simple - all you need to do is move the redirect code to the top of the page:
<?php
define('INCLUDE_CHECK',true);
require '../config/connection.php';
session_name('ppRemember');
session_set_cookie_params(86400);
session_start();
$trans = $_SESSION['transaction_id'];
$clientId = $_SESSION['id'];
//get value from database. if is pending then display loading else display summary. if is complete but no session set say session has expired
if (isset($_SESSION['txnId'])) {
if ($_SESSION['txnId']==true) {
header('Location: ../confirmation');
die();
}
} else {
while (!$_SESSION['txnId']) {
$mysqli = new mysqli("localhost", "#####", "#####", "######");
$stmt = $mysqli->prepare("
SELECT `txn_id`
FROM `trans` AS t, `order_table` AS ot, `customer_order_details` AS cod
WHERE t.transaction_id = ?
&& t.transaction_id = ot.transaction_id
&& ot.customer_order_details_id = cod.customer_order_details_id
&& cod.client_id = ?
");
$stmt->bind_param('ii', $trans, $clientId);
if ($stmt->execute()) {
$stmt->store_result();
$num_rows = $stmt->num_rows;
if ($num_rows>=1) {
$stmt->bind_result($txnidrow);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
$_SESSION['CARRYTXNID'] = $txnidrow;
$_SESSION['txnId'] = true;
}
}
}
}
header('Location: ../confirmation');
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="basket-empty" title="Success" style="display:none;">
<p>Basket emptied</p>
</div>
<div id="confirm-empty" title="Confirm" style="display:none;">
<p>Are you sure you want to empty your basket?</p>
</div>
<div id="page-wrapper">
<div id="page">
<div id="header" class="without-secondary-menu">
<div class="section clearfix">
<div id="logo-caption">
<a href="/" title="Home" rel="home" id="logo">
</a>
</div>
<div id="caption">
</div>
<div id="main-menu" class="navigation">
<ul id="main-menu-links" class="links clearfix">
<li class="menu-2 active-trail active"> Order Online </li>
<li class="menu-9"> My Account </li>
<?php if (!$_SESSION['id']) {?>
<li class="menu-10"> Sign In </li>
<?php } ?>
<li class="menu-5"> Get a Quote </li>
<li class="menu-6"> Contact Us </li>
<li class="menu-11"> News </li>
<li class="menu-8"> Uploads </li>
<li class="menu-7"> Downloads </li>
</ul>
</div>
</div>
</div>
<?php if (isset($_SESSION['id'])) { ?>
<div id="panel" class="clearfix">
<div id="account-links">
<ul class="username">
<li><span class="account-links">You are logged in as <b><?php echo $_SESSION['username']; ?></b></span>
<span class="logout">Logout</span></li>
</ul>
</div>
</div>
<?php } ?>
<div id="main-wrapper" class="clearfix">
<div id="main" class="clearfix">
<div class="content">
<a id="main-content"></a>
<div class="tabs">
</div>
<div class="region region-content">
<div id="block-system-main" class="block block-system">
<div class="content">
<div id="node-1" class="clearfix">
<div class="content clearfix">
<?php if (!isset($_SESSION['txnId'])) {
if (isset($_SESSION['cart'])) { ?>
<div class="loading2" style="height:300px;">
<span class="text2"><font size="6pt"><b>Loading....</b></font></span>
<img src="../images/ajax-loader2.gif"/><br />
<font size="3pt"><b>Please wait a moment whilst we process your payment</b></font><br />
<font size="1pt"><b>Click here to reload after 10 seconds</b></font>
</div>
<?php }
} ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer-wrapper">
<div class="section">
<div id="footer" class="clearfix">
<div class="region region-footer">
<div class="block">
<div class="content">
<div class="column1">
</div>
<div class="column2">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
$bool = false;
while (!$bool) {
//do you stuff
// when condition is met then $bool = true;
// and double check
if ($bool)
break; //or header ('location'...);
}
// or here header location
If I understood correctly, this should help.
Try it like this:
<?php
ini_set('error_reporting', E_ALL);
define('INCLUDE_CHECK',true);
require '../config/connection.php';
session_name('ppRemember');
session_set_cookie_params(86400);
session_start();
$trans = $_SESSION['transaction_id'];
$clientId = $_SESSION['id'];
if (!isset($_SESSION['txnId'])){
while ($_SESSION['txnId']!=true) {
$mysqli = new mysqli("localhost", "#####", "#####", "######");
$stmt = $mysqli->prepare("SELECT `txn_id` FROM `trans` AS t, `order_table` AS ot, `customer_order_details` AS cod WHERE t.transaction_id=?
&& t.transaction_id = ot.transaction_id && ot.customer_order_details_id = cod.customer_order_details_id && cod.client_id=?");
$stmt->bind_param('ii',$trans,$clientId);
if ($stmt->execute()) {
$stmt->store_result();
$num_rows = $stmt->num_rows;
if ($num_rows>=1) {
$stmt->bind_result($txnidrow);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
$_SESSION['CARRYTXNID'] = $txnidrow;
$_SESSION['txnId'] = true;
header('Location: http://my-site.com/confirmation/');
die();
}
}
}
}
}
?>
The issue is not the PHP, its the fact that your trying to issue a redirect header after outputing the page headers. Your while loop is after your entire page has been written. You can get around this by turning on output buffering in you php.ini OR simply by putting you while loop before any content.

Categories