0

I have a suggestion search box which has the following code:

HTML

<input style="margin-right: 10px;height: 21px;" type="text" 
       placeholder="Persons First Name" name="individual_name" id="individual_name" 
       onfocus="clearField(this, this.placeholder)" 
       onkeyup="filter_individual_results()"/>

JavaScript

<script>
    $(function() {
        $( "#individual_name" ).autocomplete({
            source: "<?php echo base_url(); ?>frontend_individual/suggest_names",
            minLength      : 3,
            select: function( event, ui ) {
                //$('#ui-id'+i).click(filter_individual_results());
                update_input_box('individual_name',ui.item.value,'2');
                //alert('id :'+ui.item.value) ;
                //document.location.href  = base_url+"controller_name/search?keyword="+ui.item.value; do something or redirect
            },
            success : function(resp) {
                filter_individual_results();//alert("auto");
            },
            error : function() {
                alert("Oops, that didn't work. Please try again.");

            }
        });
    });
</script>

PHP

Here is the controller for suggestions:

3837: public function suggest_names() {
3838:     print_r($this->user_profile_model->suggest_names($_REQUEST['term']));
3839: }

This script is working perfectly on my local PC but when I run this search online it does not work. It keeps on giving me this error:

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index: term</p>
<p>Filename: controllers/frontend_individual.php</p>
<p>Line Number: 3838</p>

I am wondering why it works locally but not online.

João Pinho
  • 3,725
  • 1
  • 19
  • 29
Omicans
  • 531
  • 1
  • 8
  • 26
  • what do you mean by online? It can mean you published the site from you dev machine to the outside world and from outside it doesn't work or it can mean that you installed the solution in another machine and it doesn't work there, which is it? – João Pinho Jun 09 '14 at 16:39
  • by online i mean the online server. On local host it works perfectly but not on the online web link. – Omicans Jun 09 '14 at 17:29
  • 1
    have you tried out using $_GET? after that, if it works, i gave you an answer containing a link, explaining implications of using $_REQUEST instead of $_GET or $_POST... – João Pinho Jun 09 '14 at 17:32
  • check the PHP config from both machines – Adrian Preuss Jun 09 '14 at 17:44

2 Answers2

0

You should use $_GET, as the parameter is being send to the server via query string. Test it, and it will work just fine.

Why did it work locally and not when you installed the website online? Well that is related with the way that $_REQUEST works, and can be numerous reasons for that being working in your local server and not in your production server. You can find more info about the here.

Community
  • 1
  • 1
João Pinho
  • 3,725
  • 1
  • 19
  • 29
-1

before accessing the $_REQUEST['term'] value it would be wise to check if it has been set

if(isset($_REQUEST['term']))
{
     /* do code in here using $_REQUEST['term'] */
}
else
{
    /* possible code to execute when $_REQUEST['term'] has not been initiated */
    /* perhaps an error message */
}

Your php error message specifically shows an undefined index of term and gives a line number referring to a line containing $_REQUEST['term'].

KnightHawk
  • 901
  • 9
  • 18
  • Although it could be wise, it does not solve the problem, as the error is happening even when the value 'term' is being sent. Because of this I have gave you -1, as this does not contribute in anything for the users question. Consider improving your answer, and I can remove my down vote. – João Pinho Jun 09 '14 at 17:47