Having Trouble With Variable in SQL String

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
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Having Trouble With Variable in SQL String

Post by snowrhythm »

i'm having a bit of trouble with this string here:

Code: Select all

$sql = 'SELECT * FROM industry WHERE industry_name LIKE "'.$link.'%"';
i'm pretty sure it has to do with that butchered-up LIKE statement...does anyone know the right syntax for that?

thanks in advance.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Its a SQL quote issue

Code: Select all

<?php
$sql = "SELECT * FROM industry WHERE industry_name LIKE '%$link%'"; 
?>
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

aha, thanks everah. i wish i would've posted that 45 minutes ago...could've saved me alot of trouble.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That's part of the learning curve my friend. In a few months, you will probably ask that question in 10 minutes (or better yet, find the answer here already [or even better yet, answer your own question as you ask it]).

Glad you got it worked out.
Post Reply