简体   繁体   中英

Escape double quotes inside query

I'm scratching my head with this and i can't figure what's wrong

 $result=mysql_query("SELECT * 
                     FROM `offers` 
                     WHERE 
                     (
                         type='$tran' && 
                         imob='$typeimob' &&
                         (
                           'str_replace("_"," ",$zone)'
                            LIKE CONCAT('%',area,'%')
                         )
                     ) 
                     ORDER BY `price` DESC 
                     LIMIT 0, 50;");
    }

This is inside a php. The problem is that I have to escape the double quotes inside str_replace, and i tried str_replace(\\"_\\",\\" \\",$zone) but it doesn't work.

Any idea?

Thanks

You need to concatenate the output of str_replace() into your string.

    $result=mysql_query(
        "SELECT * 
        FROM `offers` 
        WHERE 
        (
        type='$tran' &&
         imob='$typeimob' &&
         (
            '".str_replace("_"," ",$zone)."' 
            LIKE CONCAT('%',area,'%')
            )
        ) 
        ORDER BY `price` DESC LIMIT 0, 50;");

By the way, if you are using an IDE like Eclipse PDT, these things will be apparent to you right away :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM