Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-06-07 07:15:39

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

safe_rows question

OK – so I have the following mysql querie but it is failing

$query = safe_rows('name, title', 'txp_category', 'type like "image" AND name!="root" AND name!="peaches-and-cream"');

It is failing due to the name with hypens, if I remove it, it works fine, if I add another category name without hyphens, it works fine.

Am I doing something wrong here?

Offline

#2 2012-06-07 08:38:04

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: safe_rows question

You should probably escape the query (“peaches\-and\-cream”) with doSlash().

Offline

#3 2012-06-07 09:53:33

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: safe_rows question

Thanks etc – that worked perfectly :)

I couldn’t find any info on doSlash(), but tried addslashes() and that worked :)

Offline

#4 2012-06-07 11:20:35

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: safe_rows question

tye wrote:

I couldn’t find any info on doSlash(), but tried addslashes() and that worked :)

As Nathan Drake would say No no no no no. doSlash() is Textpattern’s core function and is used to escape quoted values used in SQL statements. You really should use it instead of addslashes(), which is not exactly the correct tool (or safe either).

Last edited by Gocom (2012-06-07 11:26:08)

Offline

#5 2012-06-07 11:31:06

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: safe_rows question

whoops…. hides :)

Thanks Jukka – I’ll check it tomorrow :)

Offline

Board footer

Powered by FluxBB