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 8795623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:25:45+00:00 2026-06-13T23:25:45+00:00

I have a script where I’m trying to match the droppable data I retrieved

  • 0

I have a script where I’m trying to match the droppable data I retrieved in the form of an ajax $.post request that contains a firstname, lastname, description and grade and match it with that of the same data in my database. In doing so I want to find the user and fetch them out in my query. I’m having trouble making an efficient query using LIKE and am unsure what other component to add to make this happen correctly

if (isset($_POST['data'])){
    $data = $_POST['data'];
    $query = mysql_query("SELECT * FROM `tempusers`
        WHERE `firstname` LIKE '%" . $data . "%'
            OR `lastname` LIKE '%" . $data . "%'
            OR `description` LIKE '%" . $data . "%'
            OR `grade` LIKE '%" . $data . "%'");

    if (! $query){
        echo'Database error: ' . mysql_error();
    }

    while ($row=mysql_fetch_assoc($query)) {
        $description = $row['description'];
        echo $description;
    }

    exit;
}

The problem is that I am not returning any results and instead getting the errors

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntaxandmysql_fetch_assoc() expects parameter 1 to be resource, boolean given.

I welcome any tips that I can implement and wouuld greatly appreciate it

  • 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-13T23:25:47+00:00Added an answer on June 13, 2026 at 11:25 pm

    The query’s syntax is valid, that means you have a single quote somewhere in your input data, causing the query to fail with the syntax error.

    To solve that you can pass your $data through mysql_real_escape_string() which will escape any quotes, and most importantly prevent SQL Injection.

    Even better than escaping would be to use a parameterised query with PDO or MySQLi.

    As for optimisation, you can try REGEXP instead of multiple LIKE’s. Example here.

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

Sidebar

Related Questions

I have script that removes an h4 element then animates a hidden form in
I have a script that retrieves objects from a remote server through an Ajax
I have script that gets some data using DBI's fetchall_hashref(). Usually it returns a
I have a sh/bash script that needs to call a batch file with parameters
I have a small JavaScript validation script that validates inputs based on Regex. I
Say I have script, that does long polling on server to check if user
I currently have script that slides down a once the page has loaded. So
We have an editor template that contains approx 40 lines of jquery. I tried
I have script similar to this: $.each( data.d, function( index, data ) { $(#results).append(
We have script http://site.com/ourscript.php How to add something like enter password block on that

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.