开发者

Mysql query containing a php array key? ie. "WHERE profession = $user['profession'] "

How do i deal with something like this:

"SELECT skills FROM jobs WHERE profession = $user['profession']"

where profession is a s开发者_JAVA百科tring...


Just use

"SELECT skills FROM jobs WHERE profession = '{$user['profession']}'"

PHP allows you to mix quotation marks like that

Note Assuming all the security checks and validations are done before this bit


Another alternate way

"SELECT skills FROM jobs WHERE profession = 
'".mysql_real_escape_string($user['profession'])."'";

If you don't need mysql_real_escape_string() just remove it.

 "SELECT skills FROM jobs WHERE profession ='".$user['profession']."'";


$profession = mysql_real_escape_string( $user['profession'] );
$query = 'SELECT skills FROM jobs WHERE profession = "' . $profession . '"';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜