Pass string from submit button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Pass string from submit button

Post 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);
 }
 ?>

User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Pass string from submit button

Post 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.
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Re: Pass string from submit button

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Pass string from submit button

Post by Benjamin »

Simmer down chief.

Where are you stuck?
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Re: Pass string from submit button

Post by Richard_in_Az »

:banghead: :banghead: :banghead: :banghead: :banghead: :banghead:

Please feel free to read the first post of this thread.
When the submit button is pressed, what has to follow to pass the entered items on to the next code so the items can be verified through the array?

Simple right?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Pass string from submit button

Post by Benjamin »

Have you checked the manual?
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Re: Pass string from submit button

Post 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?
Richard_in_Az
Forum Newbie
Posts: 12
Joined: Wed Apr 14, 2010 2:12 am

Re: Pass string from submit button

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Pass string from submit button

Post 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?
gurisingh
Forum Newbie
Posts: 1
Joined: Wed Apr 14, 2010 5:10 pm

Re: Pass string from submit button

Post 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 :).
Post Reply