0

Can anyone explain where my problem is here? im trying to create a link so that the user can go onto create a forum post

 include_once("DBconnect.php");
 $cid = $_GET['cid'];

 if (isset($_SESSION['uid'])){
     $logged .= "  <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
 }else{
     $logged .= "  Please log in to create topics in this forum";
 }
user3501382
  • 19
  • 1
  • 5

4 Answers4

2

Initialize the variable before you use it

 $logged = ''; //<--- Add here
 if (isset($_SESSION['uid'])){

Since you are using .= , it will check whether $logged has previously been assigned a value to be appended with your new value.. since there is no such value associated with $logged variable , you get that notice.

Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
1

You are appending to logged but it is not defined try puttting

$logged="";

Before the if statement

smistry
  • 1,127
  • 1
  • 9
  • 9
1

$logged .= "…" is shortcut for $logged = $logged . "…", which includes reading of $logged. This causes the mentioned notice if $logged is undefined.

Initialize $logged with a value before reading it like with an empty string:

$logged = "";
Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

Change Your Code to this

<?php
include_once("DBconnect.php");
 $cid = $_GET['cid'];
$logged = '';
 if (isset($_SESSION['uid'])){
     $logged .= "  <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
 }else{
     $logged .= "  Please log in to create topics in this forum";
 }
?>

OR Initialize the variable $logged instead of appending value in it . if $logged dose't contain any value before .

<?php
include_once("DBconnect.php");
 $cid = $_GET['cid'];
 if (isset($_SESSION['uid'])){
     $logged = "  <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
 }else{
     $logged = "  Please log in to create topics in this forum";
 }
// this will print the variable on your page 
 echo $logged;
?>
Azeem Hassni
  • 885
  • 13
  • 28