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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:50:56+00:00 2026-05-24T15:50:56+00:00

I have a searching form that the user should enter a word. Till now

  • 0

I have a searching form that the user should enter a word. Till now it works just fine but when I enter a word with 2 or more white spaces the query returns none (empty).

    $search = $_POST['srch'];

    if (!$search == "")
    {
    $con = mysql_connect('nnnnn', 'nnnnn', 'nnnn');
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("nnnnnnn", $con);
    $search = mysql_real_escape_string($search);

    $sql = "SELECT * FROM `computers` WHERE `MODEL` REGEXP '$search|$search\$' OR
    `DESCR`\n"
        . "REGEXP '^$search|$search\$' LIMIT 0, 30 ";
    // here check if there is any content
if (mysql_fetch_array($result))

{

while($row = mysql_fetch_array($result))

{// here just echoing the returned content 

}

}else echo "not found";

    }echo "enter a word"! ;

So if I enter core 2 for example it retruns all the matching results.

But if I write core 2 dou it doesn’t return anything, not even the “Not found error”.

How can I fix this?

I tried the PHPMyAdmin by replacing the $search

and the query return matches even with core 2 dou and even with adding messy words like

core 2 dou computers

i am sure the problem is in the php way of sending the query or handling it i just cant figure it out

  • 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-05-24T15:50:57+00:00Added an answer on May 24, 2026 at 3:50 pm

    Since you said any help would be appreciated, if you just want to search for a string, an easier way is to use LIKE instead of REGEXP, for example,

    MODEL LIKE '%$search%'
    

    also, I’m not sure why you’re repeating $search separated by a ‘|’

    incidentally, if multiple spaces are the problem, it’s easy to replace with single space, like this:

    $search = implode(' ', preg_split("/\s+/", $search));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an normal form that you can enter a user´s fullname in
I have been searching for quite a bit now but I have never been
I have a form that allows the user to either upload a text file
Have been searching how to convert a dictionary to a string. But the results
I have been searching for a command that will return files from the current
I have tried searching over the internet about this problem but not able to
I have been searching for an answer and trying out stuff for days now
I'm using form for searching in db. The searching is going as the user
From the image below. It can be seen that I have three table User,
I have been searching for a while now and cant find this. what I

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.