Slashes - MySQL doesn't like them so use stripslashes()?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Slashes - MySQL doesn't like them so use stripslashes()?

Post by mjseaden »

Hi,

I'm trying to record a data element into a MySQL database which includes forward slashes ('/').

Am I correct in that MySQL doesn't like / characters in text fields, and so you have to use stripslashes(), or is there some other way?

Many thanks

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

forward slashes don't matter... it's quotes which are duplicates of the ones used to create the mysql string that are the problem.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

I get an error for the following query :-

SELECT PageID FROM 4e58fbc769d276713def15dbd0065de6 WHERE PageURL='http://uk.yahoo.com/'

???

Many thanks

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what does the error say?
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Code: Select all

Error: Could not perform MySQL query - You have an error in your SQL syntax near '4e58fbc769d276713def15dbd0065de6 WHERE PageURL='http://uk.yahoo.com/'' at line 1
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that has to do with your table name... place it in backticks: `

note ` is not '
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

weird - why is that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's not recognized natively as a table's name.... or rather a reference to data for MySQL
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

You may be able to use entities. Give it a try!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

SELECT PageID FROM 4e58fbc769d276713def15dbd0065de6

woooow, in that case i would choose a different table name.
as already mentionned, escaping with backtick the name will do too.
Post Reply