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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:57:33+00:00 2026-05-23T01:57:33+00:00

I have built a search engine using php and mysql. Problem: When I submit

  • 0

I have built a search engine using php and mysql.

Problem:
When I submit a word with an apostrophe in it and return the value to the text field using $_GET the apostrophe has been replaced with a backslash and all characters after the apostrophe are missing.

Example:
Submitted Words: Just can't get enough
Returned Value (Using $_GET): Just can\
Also the url comes up like this:search=just+can%27t+get+enough

As you can see the ‘ has been replaced with a \ and get enough is missing.

Question:
Does anybody know what causes this to happen and what is the solution to fix this problem?

The code:
http://tinypaste.com/11d62

  • 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-23T01:57:34+00:00Added an answer on May 23, 2026 at 1:57 am

    From your description of “value to the text field” I speculate you have some output code like this:

     Redisplay
     <input value='<?=$_GET['search']?>'>
    

    In that case the contained single quote will terminate the html attribute. And anything behind the single quote is simply garbage to the browser. In this case applying htmlspecialchars to the output helps.

    (The backslash is likely due to magic_quotes or mysql_*_escape before outputting the text. I doubt the question describes a database error here.)


    Update: It seems it’s indeed an output problem here:

      echo "<a href='searchmusic.php?search=$search&s=$next'>Next</a>";
    

    Regardless of if you use single or double quotes you would need:

      echo "<a href='searchmusic.php?search="
          . htmlspecialchars(stripslashes($search))
          . "&s=$next'>Next</a>";
    

    (Notice that using stripslashes is a workaround here. You should preserve the original search text, or disable the magic_quotes rather.)


    Okay I forgot something crucial. htmlspecialchars needs the ENT_QUOTES parameter – always, and in your case particularly:

    // prepare for later output:
    $search = $_GET['search'];
    $html_search = htmlspecialchars(stripslashes($search), ENT_QUOTES);
    

    And then use that whereever you wanted to display $search before:

      echo "<a href='searchmusic.php?search=$html_search&s=$next'>Next</a>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not using a SearchManager, but I have built my own custom search
I have a site who's search ranking has plumetted. It should be quite SEO
I have a website which is built on ASP.NET MVC and hosted on Windows
I have an entity with a selfreferencyproperty and I wanted to search with a
I'm trying to build a miniature engine that will allow a search query to
I have recently built a list view which shows a number of products taken
I have a gridview on my page that gets bound to user search results.
EDIT: I came across a confirmation of what I suspected: Using the twitter search
I'm trying to build a custom search form for an e-commerce setup built on
Friends text box with autocomplete script (which supports multiple word completion from userstable fullname

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.