会话用户名仅在使用按钮后有效

I have a code and want to edit it. Now I try to change stuff, but I dont get why it worked before and now it doesn't anymore. First I had this:

    <?php
session_start();
$mysqli = new mysqli("localhost", "root", "usbw", "accounts");
$mysqli2 = new mysqli("localhost", "root", "usbw", "forum");
$alles_goed=false;

if (isset($_POST['title'])) {
    $alles_goed=true;
    $description=$_POST['description'];
    $title=$_POST['title'];
    $username=$_SESSION['username'];
    $usernamecheck = $mysqli->query("SELECT * from account_information where username ='". $username ."'");
//etc

This was my edit:

    <?php
session_start();
$mysqli = new mysqli("localhost", "root", "usbw", "accounts");
$mysqli2 = new mysqli("localhost", "root", "usbw", "forum");
$alles_goed=false;
$username=$_SESSION['username'];
$usernamecheck = $mysqli->query("SELECT * from account_information where username ='". $username ."'");


if (isset($_POST['title'])) {
    $alles_goed=true;
    $description=$_POST['description'];
    $title=$_POST['title'];
    //etc

This should work fine right? Still for some reason I get this error:

Undefined index: username

at:

$username=$_SESSION['username'];

What am I doing wrong and why isn't the second one possible?

EDIT:

I want to not show my form when the SESSION doesn't exists. So I got that but I want the errors gone.

Use this

if(isset($_SESSION['username'])){
    $username = $_SESSION['username'];
}

can you please check value is assigned in $_SESSION['username'] or not?

the reason is you didn't assign value to $_SESSION['username'], I think on you can print_r($_SESSION) after session_start(); to see the SESSION variable on both page.

It seems that when isset($_POST['title']) is false isset($_SESSION['username']) is also false