Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2007, 02:33 AM
Registered User
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help needed for variables containing apostrophe

I'm using php and I can't figure out how to search for exact names. some values in the variable may contain apostrophes. Here's my code so far:
$query1 = mysql_query("SELECT * FROM Names where Name = '$Name' AND `index` !=$iIDs");

variable that may contain apostrophes is :$Name

The values containing the apostrophes are the problem. E.g (O'Leary, O'brien). Those without the apostrophes, I am able to do the search.
Please help. Thanks

 
Old July 7th, 2007, 08:46 AM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here you go buddy
Code:
$query1 = mysql_query("SELECT * FROM Names where Name = \"".$Name."\" AND index !=".$iIDs);
the \" you can use for a double quote inside the double quote argument

__________________________________________________ ________
I am DJ Kat...that's my name. Its a D and a J and a Kat with a K.
 
Old July 7th, 2007, 11:18 AM
Registered User
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, Thanks for the code. But it still doesn't work. I'm thinking its maybe because some of the names in the variable has spaces like ("David O' Leary", "DJ's Station")

 
Old July 7th, 2007, 05:48 PM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think it should work why not echo your $query1 and try to put the query in manually with phpmyadmin or mysql querybrowser then you will see what the error in your SQL is

__________________________________________________ ________
I am DJ Kat...that's my name. Its a D and a J and a Kat with a K.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you translate an apostrophe? IronStar XSLT 2 November 13th, 2006 12:35 PM
cdonts and apostrophe bostonrose Classic ASP Components 3 October 23rd, 2006 08:20 AM
Apostrophe in a textarea myself Classic ASP Professional 9 June 8th, 2006 07:32 AM
Apostrophe in textarea Renu ASP.NET 1.0 and 1.1 Basics 3 September 8th, 2004 02:13 PM
Help needed with variables and functions interrupt Javascript How-To 2 May 24th, 2004 08:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.