2016-02-11 36 views
0

试图使用户能够将其个人资料的主题更改为任何他们喜欢的内容。它行不通。当一个用户改变他/她的背景时,它会影响其他用户配置文件。关于如何实现的任何想法。我的代码如下所示。当前用户的自定义背景

<?php 
    global $current_user; 

    get_currentuserinfo(); 

    // User Background Choice 

    if ($current_user->user_cutom_background= "Sports") 
    { 
     $myBg= "image.jpg"; 
?> 
    <style type="text/css"> 
    body { 
    background-image: url("<?php echo $myBg;?>"); 
    } 

    </style> 

<?php } ?> 
+0

保存为每个用户定制bg在其用户表中的特定用户数据集中并加载该数据。 –

+0

'$ current_user'对象来自哪里?您尚未创建它,并且您尚未将其设置为此用户 – RiggsFolly

+0

如果您不知道如何在用户表中创建列并在其中保存/检索数据,那么您可能应该查看一些基本教程。 –

回答

2

您正在使用赋值运算符而不是相等运算符。

相反的 -

if ($current_user->user_cutom_background= "Sports")

if ($current_user->user_cutom_background == "Sports")

为了消除这种错误,你可以先放值这样的 -

if ("Sports" == $current_user->user_cutom_background)

这样,如果你会做

if ("Sports" = $current_user->user_cutom_background)

它会抛出一个错误