Jump to content

Recommended Posts

Hello, I have data in an My SQL database that has an apostrophe in it eg: TJ's

 

right now I have the following code

$namesearch = mysql_real_escape_string($_POST['name']);
$query = "SELECT * FROM pilot WHERE name='$namesearch' ";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) )
{
include 'show.php';
}
else
{
}

 

It does not come back finding any thing and if I echo $namesearch I get TJ\\\'s

How do I get it to search for TJ's rather then TJ\\\'s?

Edited by tjverge
Link to comment
https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/
Share on other sites

It IS SEARCHING FOR TJ'S. Jesus Christ.

 

I know what it should be doing. I would not be asking for help if it was working right :( I'm closing this thread as you are not being at all helpful and being kind of on the rude side, I understand you think your helping, but in this case I don't believe you understand the problem. Thank you for trying.

Link to comment
https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413948
Share on other sites

You haven't given us enough information to help you.

 

And you definitely don't understand how escaping certain characters works. You MUST have a \ in front of a quote in order to submit that quote within a string. That's what escape_string DOES. It adds the slashes. (It does some other stuff too).

 

When you send it to SQL, it knows you mean "TJ's" because the \ ESCAPES the ' so it can see it as INSIDE the string, not ENDING the string. 

 

I suggested a solution, and you didn't bother to try it or tell us you did, you haven't told us WHY you think it's not working, you haven't shown any data or error messages. Why would anyone be able to solve your problem when as far as you've stated it THERE IS NO PROBLEM.

Link to comment
https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413954
Share on other sites

It seems to me like the $_POST value is being escaped twice.

Use get_magic_quotes_gpc to retrieve the value of the magic_quotes_gpc option in the master php.ini file.

If it returns a 1, it should be disabled.

 

Edit: seems like I took too long with my response, glad you solved the problem.

Edited by AyKay47
Link to comment
https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413957
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.