-4
  <?php 

        if($_SESSION['username'] == NULL)
        {
            print "Нямаш права да си тука";

        }
        else
        {
        if(isset($_POST['add']))


    {
        $time = time();
        $title = htmlspecialchars($_POST['title']);
        $content = strip_tags($_POST['content']);
        $q = "INSERT INTO posts(title,content,author,added) VALUES('$title','$content','Papazov','$time')";
        mysql_query($q) or die (mysql_error());
        ?>

Why it says

Notice: Undefined index: username in C:\xampp\htdocs\MatchZone2\Addpost.php on line 17

for the index in the session in the begging ?

user3027778
  • 15
  • 1
  • 5
  • 2
    Have you tried to google such a error message? **EVERY** single newbie asks about it, you're not unique – zerkms Jan 23 '14 at 01:30
  • Note #1: make sure to correctly "start" the session each PHP load - otherwise the data truly will end up missing. – user2864740 Jan 23 '14 at 01:33
  • Note #2: the SQL snippet is fundamentally flawed. See [How can I prevent SQL injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – user2864740 Jan 23 '14 at 01:34

2 Answers2

1

$_SESSION['username'] is undefined, so it's giving you undefined.

This would be correct:

if(isset($_SESSION['username'])) {

}
sunshinekitty
  • 2,307
  • 6
  • 19
  • 31
1

You're trying to read an index that doesn't exist in the $_SESSION array. Add if(!isset($_SESSION['username']))

Your code would then become:

if(!isset($_SESSION['username'])
{
    // I can't read the following, but I assume it should be displayed if the username is missing.
    print "Нямаш права да си тука";

}
else
{

}

For more on isset

emsoff
  • 1,585
  • 2
  • 11
  • 16