1

I want to use session variable in another page. I used data which is got from database to store in variable. When I try to use it another page error god undefined index. Code is below. help me to solve this

    <?php
    session_start();
    require('dbconnection.php');
    $output='';
    $sql="select * from vacancy";
    $res=mysqli_query($conn,$sql);
    if(mysqli_num_rows($res)>0){

    while($row=mysqli_fetch_assoc($res)){
    $imageno=$_SESSION[$row['vacancyid']];
    ?>

other.php page

    <?php
    session_start();
    ?>
    <div>
    <?php

    $src='images/vacancy/'.$_SESSION["imageno"].'.jpg';
    echo "<img src='".$src."'>";
    ?>
    </div>
1
  • You need to store $imageno in session variable!! Commented May 1, 2017 at 13:25

2 Answers 2

4

This isn't setting a session variable, it's trying to read one:

$imageno=$_SESSION[$row['vacancyid']];

It sounds like you meant to do this instead:

$_SESSION["imageno"] = $row['vacancyid'];

That is, to read the database row and set the value to the session.

Sign up to request clarification or add additional context in comments.

Comments

0

To get user details for every page you have to include this in your every page

   <?php
session_start();
require('dbconnection.php');
$output='';
$sql="select * from vacancy";
$res=mysqli_query($conn,$sql);
if(mysqli_num_rows($res)>0){

while($row=mysqli_fetch_assoc($res)){
$_SESSION["imageno"] = $row['vacancyid'];
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.