1

I can echo the session name so i know its working but it doesn't work in a MySQL query. I even tried turning it into a variable and its still not working:

File list: index.php response.php

$repname = $_SESSION['name'];
$sql = "SELECT * FROM `employee` WHERE rep='".$repname."' ";

also

$sql = "SELECT * FROM `employee` WHERE rep=".$_SESSION['name']." ";

any ideas on what's wrong?

UPDATE**

Here's the right query

        $sql = "SELECT * FROM `employee` WHERE rep='".$_SESSION['name']."' ";

I know its the right query because now i'm getting records to display but its only records where rep is blank. This means i'm not getting the session name for some reason.

I tried adding:

     session_start();
 if(isset($_GET['name'])){
 $_SESSION['name']=$_GET['name'];
  }

But im still only getting records where rep is blank

6
  • No errors? And I think you mean $repname = $_SESSION['name'] not $_SESSION['name'] = $repname Commented Apr 11, 2017 at 3:45
  • i don't see any errors :( Commented Apr 11, 2017 at 3:52
  • 1
    if its a string, then you should properly quote it, you do know that it unsafe, you should prepare the statement instead Commented Apr 11, 2017 at 3:52
  • its having value or not in $repname or $_SESSION['name'] ? Commented Apr 11, 2017 at 3:53
  • 1
    ... don't see any errors... you mean, apart from the apparent SQL Injection vulnerability. ie. what happens when the value in $_SESSION['name'] happens to contain a quote e.g.."O'Reilly". Of course, we only see code that sets a variable to a string. We don't see any code that attempts to execute that SQL statement. Commented Apr 11, 2017 at 3:58

1 Answer 1

1

Be sure to add session_start() to the top of your session to initiate your session start

    <?php
    session_start(); ?>

Also be sure to add this to retrieve your name field:

<?php 
     session_start();
     if(isset($_GET['name']){
     $_SESSION['name']=$_GET['name'];

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

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.