0

i recently developed a login-registration form for my site by using php but came up with the following errors.

Notice: Undefined index: action in C:\xampp\htdocs\login\login.php on line 3
Notice: Undefined index: reg in C:\xampp\htdocs\login\login.php on line 24
Notice: Undefined index: action in C:\xampp\htdocs\login\login.php on line 29
Notice: Undefined index: msg in C:\xampp\htdocs\login\login.php on line 40

this code is working fine and sends and retrieve data from database but i really have no idea why he gives me these errors. below is the code

<?php
require_once('load.php');
if ( $_GET['action'] == 'logout' ) {
    $loggedout = $j->logout();
}

$logged = $j->login('index.php');
?>
<html>
<head>
    <title>Login Form</title>
    <style type="text/css">
        body { background: #c7c7c7;}
    </style>
</head>

<body>
    <div style="width: 960px; background: #fff; border: 1px solid #e4e4e4; padding: 20px; margin: 10px auto;">
        <?php if ( $logged == 'invalid' ) : ?>
            <p style="background: #e49a9a; border: 1px solid #c05555; padding: 7px 10px;">
                The username password combination you entered is incorrect. Please try again.
            </p>
        <?php endif; ?>
        <?php if ( $_GET['reg'] == 'true' ) : ?>
            <p style="background: #fef1b5; border: 1px solid #eedc82; padding: 7px 10px;">
                Your registration was successful, please login below.
            </p>
        <?php endif; ?>
        <?php if ( $_GET['action'] == 'logout' ) : ?>
            <?php if ( $loggedout == true ) : ?>
                <p style="background: #fef1b5; border: 1px solid #eedc82; padding: 7px 10px;">
                    You have been successfully logged out.
                </p>
            <?php else: ?>
                <p style="background: #e49a9a; border: 1px solid #c05555; padding: 7px 10px;">
                    There was a problem logging you out.
                </p>
            <?php endif; ?>
        <?php endif; ?>
        <?php if ( $_GET['msg'] == 'login' ) : ?>
            <p style="background: #e49a9a; border: 1px solid #c05555; padding: 7px 10px;">
                    You must log in to view this content. Please log in below.
                </p>
        <?php endif; ?>

        <h3>Login</h3>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <table>
                <tr>
                    <td>Username:</td>
                    <td><input type="text" name="username" /></td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><input type="password" name="password" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="Login" /></td>
                </tr>
            </table>
        </form>
        <p>Not a member? <a href="register.php">Register here</a></p>
      </div>
    </body>
 </html>
arcade
  • 213
  • 1
  • 13

1 Answers1

2

You are sending your form as POST, but you are reading the content as GET, you should either change your form's action to GET, or retrieve your data from $_POST instead of $_GET.

You could either change:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

To:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">

or change all your $_GET to $_POST

taxicala
  • 21,408
  • 7
  • 37
  • 66