0
<?php
session_start();
ob_start();
echo "0LIV3R 's first game";
require("DatabaseObject.php");
require("databaseVars.php");
$database= new DatabaseObject($host, $username, $password, $database);

if(!isset($_SESSION['user_id']) && $_POST['login'])
{
    $username=$database->clean($_POST['username']);
    $password=$database->clean($_POST['password']);

    $result = $database->query("SELECT 'id','username','password' FROM 'users' WHERE 'username'='$username' LIMIT 1");
    try{
        if($database->num_rows($result) == 0){
            throw new Exception('User doesnot exist!');
        }
        $user = $database->fetch($result);
        if(md5($password) != $user['password']){
            throw new Exception('Invalid username/password!');
        }
        $_SESSION['user_id'] = $user['id'];

    }catch (Exception $e){
        echo $e->getMessage();
    }
}
/*DISPLAY*/
//echo"<h3 style='text-align:center;'>WAR LEGENDS</h3>";
$output = ob_get_clean();
require('templates/header.php');
echo "<p style='text-align:center;'>". $output ."</p>";

if(!isset($_SESSION['user_id'])){
    //require('templates/layout.php');
    echo "Welcome to War Legends<br/>";
}
else{
echo"<form action='./' method='POST'>
Username: <input type='text' name='username'/><br/>
password: <input type='password' name='password'/><br/>
<input type='submit' name='login' value='Register'/>
</form>";
}
require('templates/footer.php');

?>

i was trying to code online rpg login and got error in index i cant find a solution pls help this is my code and i donno how to fix this ( ! ) Notice: Undefined index: login in C:\wamp\www\myrpg\index.php on line 9 this is error

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74

2 Answers2

0

It means that the array $_POST doesn't has an element named login. So please check why this happens. Probably it is because the posted form doesn't have this.

ch271828n
  • 15,854
  • 5
  • 53
  • 88
0

In your First if you are using $_POST['login'] - try using it with !empty() or isset() function like this: !empty($_POST['login'])

dieBeiden
  • 178
  • 6