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
Multi language - seo links
Im trying to figure out the best method to have a multi language website that will function with seo
Feed Maker
Hi all.
First of all I must say I am not a php developer so I am afraid I don't know much about i
problem in program for counting no of chars using pointers
Hi all, I was trying to make a program which counts number of chars in a string using concpt of poin
quick question
Hi ..
i have a question
how do i set a var so it displays via an echo
Code: $logo = '&a
Install page
How do I make it so when a user submits information on the Install page, it'll right it into the cor
problems with php variables in mysql query
i can't seem to get the following query to work.
select $q1c from $vote_rate where id = $re
I apologise! It's a newbie to PHP feedback form problem!
Hi,
I am a total newbie to PHP. I am also a unemployed and need to get a job. So after 100% r
image upload, resize THEN submit form
Ok so I have a form that requires the user to upload an image, and then do something with that image
What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin
disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte