Compare user input to flat file data
Posted on
16th Feb 2014 07:03 pm by
admin
Help...Am a complete newbie to programming so my code is prolly quite long. Am trying to verify a users details entered into a login form against details stored in an existing flat file.
No matter what I input, I get "not registered", even if it does match.
What have I done wrong? I have spent 3 LOOng afternoons trying to nut this out..now am going nuts....
<?php
if ($_POST['submit']=="submit")
{
$errormessage = "";
if (empty($_POST['userName']) ||empty($_POST['password']))
{
$errormessage = "<p>Please enter a user name and password</p>";
}
else
{
$userName=trim($_POST['userName']);
$password=trim($_POST['password']);
// check user name and password
$nameFlag=false;
$passwordFlag=false;
$fp = fopen($_SERVER['DOCUMENT_ROOT']."/toys/users.txt","r" );
while (!feof($fp))
{
$line=fgets($fp,100);
($userName== $line? $nameFlag=true : $nameFlag=false);
($password==$line? $passwordFlag=true : $passwordFlag=false);
}
fclose($fp);
if($nameFlag && $passwordFlag==true)
{
$foundFlag= true;
}
else
{
$foundFlag=false;
}
($foundFlag==true?$welcome= "Welcome ".$userName." you are now logged in":$sorry= "Sorry you are not registered");
}
}
?>
// my html form below
<form method="post" action="<?=$_SERVER['PHP_SELF']?>" >
<fieldset class="outline">
<h3>Registered customers</h3>
<label>User Name:</label>
<input type="text" class="login" value="" name="userName" id="userName" />
<label>Password:</label>
<input type="text" class="login" value="" name="password" id="password"/>
<br />
<br />
<input type="submit" value="submit" name="submit" id="submit"/>
<br />
<?=$errormessage?>
<br />
</fieldset>
</form>
No comments posted yet
Your Answer:
Login to answer
255
7
Other forums
void* and sizeof()
Hi,
Using void* and sizeof is it possible to get the value of the object ?
I understan
Connect to database that isn't localhost
I am currently doing a small script for a company that doesn't have mySql support on there hosting.
compile php5 with DOM
Hi,
I can't manage to compile php 5.3.0 from source on Windows to include DOM,
in spite of
PHP Tab Control
Hi All,
I would like to have PHP tab control with/without Javascript.
But I want to r
How to generate a text file using php...?
Hi,
Can anyone give me code to generate a text file using php
Thanks in advance
Transform value 0 in no and 1 in yes help needed
Hello,
I have this in the table: "value" type int 0 to represent false and 1 to represe
Weird problem with SELECT command..Help!
Hi!
It seems I'm having a really weird problem with SQL SELECT command....I have table into a
Help with form post data and arrays
Hi all,
I am new to this forum... It has been awhile since i have worked with arrays, and i a
i have no idea why this isn't working
Code: <?php
session_start();
include("connect.php");
error_reporting(E
Calling All PHPFREAKS Blackberry Users
Are you a member of PHPFreaks and have a blackberry? Well RIM just recently released Blackberry Mes