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
Problems with returning true or false in eval()'d code
Hi guys,
Would appreciate some help with a problem when running eval() on a function that sho
SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built
help with php
It's not displaying or pulling anything out of the database.
Code: <html><
.htpasswd Registration Form
Hi,
I wanted to make an htpasswd registration form.
I found this code on the internet but have
mails going in spam??
The mails I sent to folks in my database using mail(function) are going in spam??
Any idea ho
PHP Include not working
The website is http://www.grlistingservices.com
The code block is as follows:
<
problem getting my contact form working
Yeah I know this is a pretty basic problem, but it's been a while since I've worked with PHP and I'm
array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_ma
MYSQL INSERT ID NOT WORKING
Code: $id = mysql_insert_id();
header("Location: ./?view=$id");
Why $id pulling blan
Functions Not Loading Into Div
I had some help doing some of this but what I'm trying to do is get my functions to retrieve its val