how to do triple quotoation marks

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
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

how to do triple quotoation marks

Post by MHardeman25 »

Hey, how do you handle triple quotes like this

Code: Select all

$sql = "SELECT * FROM tb_users WHERE username = '$_SESSION['username']'"
see how at the '_$SESSION['username']' has quotes around it and around username, and the whole thing is in "
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to do triple quotoation marks

Post by John Cartwright »

Code: Select all

$sql = "SELECT * FROM tb_users WHERE username = '$_SESSION[username]'";
or

Code: Select all

$sql = "SELECT * FROM tb_users WHERE username = '{$_SESSION[username]}'";
or (my preference)

Code: Select all

$sql = "SELECT * FROM tb_users WHERE username = '". $_SESSION['username'] ."'";
You should also note, you should be passing all query input through mysql_real_escape_string() to sanitize. I.e.,

Code: Select all

$sql = "SELECT * FROM tb_users WHERE username = '". mysql_real_escape_string($_SESSION['username']) ."'";
MHardeman25
Forum Commoner
Posts: 42
Joined: Mon Jul 12, 2010 10:34 am

Re: how to do triple quotoation marks

Post by MHardeman25 »

Thanks.
Post Reply