0

I am trying to make a page where users can type in a textbox the username of a user to check to see if they are banned from one of our servers.

The way I want to do this is it searches a database that contains all of the banned users and the reason they are banned. The user would type into a text box the username of the person and click search. It would then show any results. If results are found it would echo "User: Reason: Time: " but with stuff inside <> values from the database table, if nothing was found it would return "No matches found".

This can be done either through HTML, PHP, or whatever else there is to make this possible.

I tried using Creating a search form in PHP to search a database? but I got an error "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/infini60/public_html/bans/search/index.php on line 36" Any fixes or solutions would be great.

Any help is greatly appreciated.

Community
  • 1
  • 1
Imperial Knight
  • 51
  • 2
  • 2
  • 7
  • would be a snap, if you used a db –  Jan 17 '14 at 01:05
  • Yes but wouldn't that require another page where you had to add bans? And then some kind of authentication would be needed which may get complicated. Which is why I wanted to use a text file. – Imperial Knight Jan 17 '14 at 01:09
  • I don't see any barrier to perform this. Just read file line by line, and traverse through it and compare. – TwilightSun Jan 17 '14 at 01:09
  • And, if you don't want some other page to administrate the database, you can use database management clients or PHPMyAdmin. – TwilightSun Jan 17 '14 at 01:10
  • @TwilightSun Would a page that administrated the database be easy to make? It would need to be secure as well. – Imperial Knight Jan 17 '14 at 01:13
  • Use PHPMyAdmin, download it and put it under your php server, that's all you need to do. It's secure as long as your mysql database is secure. – TwilightSun Jan 17 '14 at 01:18
  • You can do that your way. But you have to take a look at txt file structure. you can do this with php via $pos = strpos(txtfile, what are you looking for) and then find new line after that with $endpos = strpos(txtfile,"\n", $pos). all between $pos and $endpos is your data – pregmatch Jan 17 '14 at 01:26
  • Do you need search by EXACT username? And, yes, .txt file should be properly structured... – sinisake Jan 17 '14 at 01:33
  • @TwilightSun I set up PHPMyAdmin and added a table with Users, Reason, and Time. Now that it is set up, how can I make a page that searches for a user based off the input and echoes back "User: Reason: Time: – Imperial Knight Jan 17 '14 at 01:43
  • http://stackoverflow.com/questions/12747650/creating-a-search-form-in-php-to-search-a-database – sinisake Jan 17 '14 at 01:55
  • @nevermind I tried using that post, but I get "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/infini60/public_html/bans/search/index.php on line 36" on search. Any fixes? – Imperial Knight Jan 17 '14 at 02:14
  • You should post your code. Also, some things in your question are left unclear, related to search nature... Should search look for exact match, or similar results should be shown, etc,etc... – sinisake Jan 17 '14 at 09:14
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – ChrisGPT was on strike Apr 08 '14 at 11:52

1 Answers1

1

Web form with a input field to enter username, a php script that queries the database and acts based on database response. Very simple indeed.

Just need one file, some form.php, which at the beginning performs validation, sanitization and query. Once the script receives database response, performs actions like echo, grant access or anything you need.

digitai
  • 1,870
  • 2
  • 20
  • 37