Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Get data from a textbox and compare it with a line in a file

Links for php scripts

Moderators: macek, egami, gesf

Get data from a textbox and compare it with a line in a file

Postby bitakid1997 » Sat Jun 21, 2014 9:50 pm

Hi, I am a newbie and i start to learn PHP Script for a few months! I'm from Vietnamese so my English is very bad!
I have a question: I want to get data from a textbox and compare it with a line data in a text file. If it 's same, a message box appear with report: "You sign in success." and if it 's not same, a message box appear with: "You don't have an account. Please register a n account.". Done!
Please help me. Thanks a lot!
bitakid1997
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Jun 21, 2014 9:37 pm

Re: Get data from a textbox and compare it with a line in a

Postby kladrian » Thu Aug 14, 2014 6:37 am

Hi,

first create a form with a text box.

In your action php you should get the value of the text box by searching it into the $_POST (or $_REQUEST) array.

Code: Select all
$text_val = $_POST['text_box_name'];


then you'll have to search it in the file; there are few ways to do that.
The ugliest and yet quickest way is
Code: Select all
$file_content = file_get_contents('/absolute/path/to/file');
if (strpos($file_content, $text_val) !== FALSE) {
  // OK
  echo "You sign in success.";
}
else {
  // KO
  echo "You don't have an account. Please register a n account.";
}


---
kladrian
kladrian
New php-forum User
New php-forum User
 
Posts: 12
Joined: Thu Aug 14, 2014 1:13 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.