Jump to content

Recommended Posts

I'm trying to add a simple feature to my website.

I don't know much about php (nor the other languages), so I need a bit "spoon feeding" :D

 

I want it to work like this:

 

I type a name into a search box and hit enter or click "search".

It searches an matching .txt document from a specific folder and displays the contains.

Also, it would be good if it wasnt case-sensitive and if theres a typo in the name it would suggest some options..

 

 

 

At the moment I have some copy pasted code which I have heavily edited without knowing exactly what to do..

You can see it here: http://pastebin.com/MhJTLbUU

If you need more information about the website or the structure etc, just ask and I will reply ;)

 

Thanks for you time!

 

- Mike

Link to comment
https://forums.phpfreaks.com/topic/241895-need-a-bit-help-with-a-simple-feature/
Share on other sites

you will probably want to store the data in a database.

It would be much easier if you pasted your code to this thread please

Yea I was thinking that also, I'm using phpmyadmin :P

 

 

    case "npc_drops":
     
     
            //if (!$post && isset($HTTP_RAW_POST_DATA))
               // $post = $HTTP_RAW_POST_DATA;
     
    echo
                            "<form method='post'><div class='table'><div class='header'><img src='infrastructure/content/images/Monster Database.png'></div></br></br><div class='content'>
                            <input type='hidden' name='query' value='npc' />
                            <table style='width:75%;margin:auto;'>
                                                   
                                                   
                            <tr>
                                    <td style='width:50%;'><font color=#000000>Type in monster name</font></br></br></td>
                                    <td style='width:50%;'><input type='text' maxlength='30' size='25' value='" . (isset($_POST['npc']) && !isset($_POST['clearit']) ? $_POST['npc'] : 1) . "' name='npc' /></br></br></td>
                                    <td><input type='submit' name='npc' value='Search' /></br></br></td>
                            </tr>
                           
     
                           
                            </form>
                            ";

your form needs an action attribute, so it knows where to send the date..

 

<form method='post' action='test.php'>

 

then on your test.php page you will have something like this

 

mysql_connect('host', 'user', 'pass'); //your credentials
mysql_select_db('test'); //you credentials

$submit_button = $_POST['npc'];

if(isset($submit_button)){ //check if the submit button has been clicked
      $name = $_POST['name']; //you need to change your textbox name from npc
      $name = mysql_real_escape_string(trim($name)); //clean up the input for insertion
      $query = mysql_query("INSERT INTO table_name VALUES('$name')"); //place inside VALUES the values that you want to insert into your db
      if($query){
            print "Successfully inserted";
      }else{
            exit(mysql_error());
      }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.