Session Name in SQL query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1330

    #1

    Tech Session Name in SQL query?

    What is the best way to include
    <?=$_SESSION['name']?>
    into an SQL query please?

    I want to do something along these lines (which isnt the correct way apparently lol):

    $con=mysqli_connect("localhost","USER","PASS","DB" );

    $result = mysqli_query($con,"SELECT * FROM Documents WHERE Writer REGEXP '<?=$_SESSION['name']?>' ORDER BY ID DESC;");

    while($row = mysqli_fetch_array($result))
    Basically, any time one of my writers logs into the admin system, I want it to display the documents they've completed based on their login name to them and I figured using the session name would be the easiest way, as it gets attached on submission and stored in the DB in the 'Writer' column, I just can't figure out how to get that info to display on a page through an SQL query
    Extreme Link List - v1.0
  • k0nr4d
    Confirmed User
    • Aug 2006
    • 9231

    #2
    Exactly the same way as any other variable

    $result = mysqli_query($con,"SELECT * FROM Documents WHERE Writer REGEXP '".mysqli_real_escape_string($con, $_SESSION['name'])."' ORDER BY ID DESC;");
    Mechanical Bunny Media
    Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1330

      #3
      Originally posted by k0nr4d
      Exactly the same way as any other variable

      $result = mysqli_query($con,"SELECT * FROM Documents WHERE Writer REGEXP '".mysqli_real_escape_string($con, $_SESSION['name'])."' ORDER BY ID DESC;");
      Ah okay, I was using the same as in my HTML code, thanks for clearing that up for me man
      Extreme Link List - v1.0

      Comment

      Working...