0

Am I loosing the plot or is something strange happening here?

I have a simple login form (see below), but when I call the page, PHP returns and undefined index error, even though I have coded to say if index is undefined, then die.

Am I missing something very obvious in PHP v 5

Form

<body>
<form method="post" action="">  
  <p align="center" class="style1">
    <label>Username
    <input type="text" name="username" />
    </label>
  </p>
  <p align="center" class="style1">
    <label>Password
    <input type="password" name="password" />
    </label>
  </p>
  <p align="center" class="style1">
     <label>Remember me
       <input type="checkbox" name="rememberme" />
    </label>    
  </p>
  <p align="center">    
    <input type="submit" name="login" value="Log in" />   
  </p>
</form>
</body>

Code:

if ($_POST['login']){
    //get date
    $username=$_POST['username'];
    $password=$_POST['password'];
    $rememberme=$_POST['rememberme'];
}else{
    die("Please enter a valid username and password and click Submit");
    }

Edited by mike_2000_17: Fixed formatting

4
Contributors
4
Replies
16
Views
7 Years
Discussion Span
Last Post by zein1212
0

Thank you to those who have offered help.

I'm not 100% sure, but it seems that the way I defined the start of a PHP string has a consequence on the code.

For example
<?
will not process my php code

<?php
will process my code but will throw errors such as "undefined index" when I declare a statement such as "if ($index){then}else(other)

<?PHP
will process all of my code.

Is there something specific I have set in my PHP.in to dictate this behavior, or is this very strange, meaning I have probably corrupted by PHP installation, and should re-install.

Again many thanks

0

Try this

<?php 
//connect to MYSQL database
include 'connection.php';
if($_POST){
         $username=$_POST['username'];
        $password=$_POST['password'];
        $rememberme=$_POST['rememberme'];

$result="SELECT * FROM  user_table WHERE username='$username' and password='$passowrd'";        

if($result != NULL){
            echo "You log in";
            // or you can use this header to redirect
            // header("location:index.php");
        }else{
        echo"Please enter a valid username and password and click Submit";
// or you can redirect to         // header("location:index.php?message=0");
        }
    }
?>

Edited by zein1212: wrong query name

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.