Page 1 of 1

Undefined index error and login always "true"

Posted: Wed May 20, 2009 5:54 am
by jmcc
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:
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
The result is also true before any username and password is entered.

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 for connections.php

Code: Select all

 
<?php
///////////////////////////
$database   =  "test";
$username   =  "username";
$password   =  "password";
//////////////////////////
 
$link   =@mysql_connect('localhost', $username, $password);
$db     =mysql_select_db($database, $link);
 
?>
 
I would appreciate any help.
Jay

Re: Undefined index error and login always "true"

Posted: Wed May 20, 2009 6:18 am
by Mark Baker
change

Code: Select all

$userid = $_POST['userid'];
to

Code: Select all

$userid = (isset($_POST['userid'])) ? $_POST['userid'] : false;
for each such occurrence

Re: Undefined index error and login always "true"

Posted: Wed May 20, 2009 3:33 pm
by Darhazer
I already replied about rowAccount here:
viewtopic.php?f=1&t=100501