Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:00:32+00:00 2026-06-17T16:00:32+00:00

I’m trying to work with AJAX autocompletes and I am having a few problems

  • 0

I’m trying to work with AJAX autocompletes and I am having a few problems with getting the two languages to work in synergy.

When I replace all the issets with only 1 $_POST the snippet below will work, however by adding another $_POST I get an error on line 5.

<?php 

require_once '../Configuration.php';
if (isset($_POST['search_term'] . $_POST['postcode']) == true && empty ($_POST['search_term'] . $_POST['postcode']) == false) {
$search_term = mysql_real_escape_string($_POST['search_term'] . $_POST['postcode']);
$query = mysql_query("SELECT `customer_name`,`postcode` FROM `Customers` WHERE `customer_name` LIKE '$search_term%' ");
while(($row = mysql_fetch_assoc($query)) !== false) {
    //loop
    echo '<li>',$row['customer_name'] . $row['postcode'] '</li>';
}
}


?>

Any advice on why it is throwing this error would be much appreciated. Thanks.

I understand I should be using mysqli, I am just trying to get the logic first 🙂

Js:

Primary.js:

$(document).ready(function() {
$('.autosuggest').keyup(function() {

    var search_term = $(this).attr('value');
    var postcode = $_GET['postcode'];
    //alert(search_term); takes what is typed in the input and alerts it
    $.post('ajax/search.php', {search_term:search_term, postcode:postcode},     function (data) {
        $('.result').html(data);
        $('.result li').click(function() {
            var result_value = $(this).text();
            $('.autosuggest').attr('value', result_value);
            $('.result').html('');

        });
    });
});
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:00:33+00:00Added an answer on June 17, 2026 at 4:00 pm

    The parameter(s) to isset() must be a variable reference and not an expression (in your case a concatenation); but you can group multiple conditions together like this:

    if (isset($_POST['search_term'], $_POST['postcode'])) {
    }
    

    This will return true only if all arguments to isset() are set and do not contain null.

    Note that isset($var) and isset($var) == true have the same effect, so the latter is somewhat redundant.

    Update

    The second part of your expression uses empty() like this:

    empty ($_POST['search_term'] . $_POST['postcode']) == false
    

    This is wrong for the same reasons as above. In fact, you don’t need empty() here, because by that time you would have already checked whether the variables are set, so you can shortcut the complete expression like so:

    isset($_POST['search_term'], $_POST['postcode']) && 
        $_POST['search_term'] && 
        $_POST['postcode']
    

    Or using an equivalent expression:

    !empty($_POST['search_term']) && !empty($_POST['postcode'])
    

    Final thoughts

    You should consider using filter functions to manage the inputs:

    $data = filter_input_array(INPUT_POST, array(
        'search_term' => array(
            'filter' => FILTER_UNSAFE_RAW,
            'flags' => FILTER_NULL_ON_FAILURE,
        ),
        'postcode' => array(
            'filter' => FILTER_UNSAFE_RAW,
            'flags' => FILTER_NULL_ON_FAILURE,
        ),
    ));
    
    if ($data === null || in_array(null, $data, true)) {
        // some fields are missing or their values didn't pass the filter
        die("You did something naughty");
    }
    
    // $data['search_term'] and $data['postcode'] contains the fields you want
    

    Btw, you can customize your filters to check for various parts of the submitted values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.