Page 1 of 1
Pass string from submit button
Posted: Wed Apr 14, 2010 2:20 am
by Richard_in_Az
I am slowly learning php on my own. I need to know what I can do to check the name and password entered in the text boxes against the records in the text file. Then when I have match, the form will be hidden from view.
If there is no match, write the name and password to the text file.
Thanks.
Code: Select all
<form action='index1.php' method=post>
<table>
<tr>
<td>User Name<input type ='text' class='bginput' name='userid' ></td>
<td>Password <input type ='text' class='bginput' name='password' ></td>
</tr>
<tr>
<td><input type='submit' value='Submit'> <input type='reset' value='Reset'></td>
</tr>
</table>
</form>
<?php
$lines = file('test.txt');
foreach ($lines as $line_num => $line)
{
print "<font color=red>Line #{$line_num}</font> : " . $line . "<br />\n";
$arr=explode(",",$line);
print_r($arr);
}
?>
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 4:40 am
by requinix
You can use
print_r to examine stuff.
This is simple. You should be able to figure it out.
There's always the
online manual if you need it.
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 11:27 am
by Richard_in_Az
Why is it that I always seem to run well meaning idiots when I ask a simple question?
Are you the class clown?
Do you think I just whipped that code out of thin air on my own? No. Actually, it is a combination of stuff I've already found on php.net and elsewhere.
I would prefer that if you're going to reply to a post with an asenine response, please keep it to yourself.
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 11:54 am
by Benjamin
Simmer down chief.
Where are you stuck?
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 12:24 pm
by Richard_in_Az
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 12:34 pm
by Benjamin
Have you checked the
manual?
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 12:51 pm
by dimxasnewfrozen
Well that php code needs to be in the index1.php file in order to get executed.
I'm not really sure what you're trying to do. You just want to display the contents of the text file when the form gets sumbited?
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 1:45 pm
by Richard_in_Az
Dude, like I think I've said that twice now. The problem is, I can't find anything in the "MANUAL" that combines the two problems and deals with it.
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 4:50 pm
by requinix
Ever heard the phrase "don't bite the hand that feeds you"?
Stop biting.
Variables from External Sources
Now: What
specifically have you not figured out how to do?
Re: Pass string from submit button
Posted: Wed Apr 14, 2010 5:24 pm
by gurisingh
Hi Dude,
In your index1.php you need to retrieve the data from the post(form).
Try putting following in your index1.php:
Code: Select all
$userid = $_POST['userid'];
$password = $_POST['password'];
Now once you've got the username and password from the user you could do a if statement in the loop:
Code: Select all
$lines = file('test.txt');
foreach ($lines as $line_num => $line)
{
print "<font color=red>Line #{$line_num}</font> : " . $line . "<br />\n";
$arr=explode(",",$line);
if ($arr == $userid) {
userid is a match
}
if($arr == $password){
password is a match
}
if (userid == true AND password == true){
hide form
}
else{
dont do anything
}
}
I am sure there is a more elegant way but this might help you develop it

.