我可以将日期与我的字符串联系起来吗?

时间:2014-04-14 20:55:13

标签: php mysql phpmyadmin

我有个人资料表单,当我的用户更新他们的个人资料时,当前日期也会被添加到个人资料的描述中。

$today = Date("l F d, Y"); 

$sqlUpdate = 'UPDATE USER_PROFILE SET 
FIRST_NAME =("'.$FIRST_NAME.'"), 
LAST_NAME=("'.$LAST_NAME.'"), URL=("'.$URL.'"), 
DESCRIPTION= CONCAT_WS(',',"'.$today.'","'.$DESCRIPTION.'") 
WHERE ID = "'.$GetID.'";';

我不确定如何在php中将日期与字符串连接起来,我将不胜感激任何帮助:)

这是错误的:

Parse error: parse error, unexpected ',' on line 122

1 个答案:

答案 0 :(得分:1)

你必须逃避引用:

$today = Date("l F d, Y"); 

$sqlUpdate = 'UPDATE USER_PROFILE SET 
FIRST_NAME =("'.$FIRST_NAME.'"), 
LAST_NAME=("'.$LAST_NAME.'"), URL=("'.$URL.'"), 
DESCRIPTION= CONCAT_WS(\',\',"'.$today.'","'.$DESCRIPTION.'") 
WHERE ID = "'.$GetID.'";';

或者您可以让DESCRIPTION列获得其实际值:

$today = Date("l F d, Y") . $DESCRIPTION; 

$sqlUpdate = "
    UPDATE USER_PROFILE SET 
        FIRST_NAME = '$FIRST_NAME'
        , LAST_NAME = '$LAST_NAME'
        , URL= '$URL'
        , DESCRIPTION = '$today' 
    WHERE
        ID = '$GetID'
";