0

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.

4

4 回答 4

1

用这个

if(isset($_SESSION['username'])){
    $username = $_SESSION['username'];
}
于 2013-10-08T07:21:47.577 回答
0

您能否检查是否在 $_SESSION['username'] 中分配了值?

于 2013-10-08T07:14:16.140 回答
0

原因是你没有为 $_SESSION['username'] 赋值,我认为你可以在 session_start() 之后 print_r($_SESSION); 在两个页面上查看 SESSION 变量。

于 2013-10-08T07:18:14.880 回答
0

似乎当 isset($_POST['title']) 为假时 isset($_SESSION['username']) 也为假

于 2013-10-08T07:18:15.413 回答