Undefined index error and login always "true"
Posted: Wed May 20, 2009 5:54 am
Hi,
Below you will find the code I wrote for a login script. I am new at php please bear this in mind.
Errors received:
Code for login.php:
Code for connections.php
I would appreciate any help.
Jay
Below you will find the code I wrote for a login script. I am new at php please bear this in mind.
Errors received:
The result is also true before any username and password is entered.Notice: Undefined index: userid in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 5
Notice: Undefined index: password in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 6
Notice: Undefined index: submitted in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 7
Notice: Use of undefined constant rowAccount - assumed 'rowAccount' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\login.php on line 17
Code for login.php:
Code: Select all
<?php
require_once("connection.php"); // database connection
// catch field data
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
if ($userid && $password) {
//////////////////////////////////
$query =sprintf("SELECT * FROM where user_name='$userid' and user_password = '$password'");
$result =@mysql_query($query);
$rowAccount =@mysql_fetch_array($result);
/////////////////////////////////
}
if (rowAccount) {
echo "The record exists so you can enter";
}elseif($submitted){
echo "You dont exists on our record";
}
?>
Code: Select all
<?php
///////////////////////////
$database = "test";
$username = "username";
$password = "password";
//////////////////////////
$link =@mysql_connect('localhost', $username, $password);
$db =mysql_select_db($database, $link);
?>
Jay