徽章原因错误

时间:2012-05-30 02:08:23

标签: php mysql html

我正试图在我们的系统上显示徽章,徽章是对用户的奖励/成就。他们在他们的个人资料中显示,有效的是图像/徽章显示,但徽章原因没有。

我试着这样做

<?
    $badgesql = mysql_query("select * from usr_badge where user = '$user'");
    $user2 = mysql_query("select * from usr_users where username = '$user'");
    $usr2 = mysql_fetch_array($user2);
    $vipsql = mysql_query("select * from usr_vip where userid = '$usr2[id]'");
    $vipcheck = mysql_num_rows($vipsql);
    $badgecheck = mysql_num_rows($badgesql);
    $checkit = $badgecheck + $vipcheck;
    if($checkit==0)
    echo("This user does not have any badges");
    else
    if($badgecheck!=0)
    {
    while($badge = mysql_fetch_array($badgesql))
    {
    echo('<a onclick="TINY.box.show({html:'Reason: '.$badge[reason].',animate:false,close:false,mask:false,boxid:'success',autohide:2,top:-14,left:-17})"><img src="'.$badge[badge].'" </a>');
    }
    }
    //Display VIP Badges
    if($vipcheck!=0)
    {
    $vipbadge = mysql_fetch_array($vipsql);
    $vip1 = mysql_query("select * from usr_vipdb where id = '$vipbadge[vipid]'");
    $vip2 = mysql_fetch_array($vip1);
        echo('<img src="'.$vip2[url].'" alt="This user is a VIP!" />');
    }
    ?>

但上面的代码不起作用。当我尝试在第167行查看页面“解析错误:语法错误,/home/**/public_html/memb.php中的意外T_STRING”时出现错误“

有人可以告诉我我做错了什么或者指出了我正确的方向吗?

提前致谢

2 个答案:

答案 0 :(得分:2)

echo开头的长行可能是错误的 - 突出显示 here 的语法被破坏了,表明你可能错误地匹配了引号或类似内容。 (将它拆开。将每个小段放在自己的行上。你不会错过那个错误。)

这是你当前的代码被打破,因为我相信解释器会解析它:

echo('<a onclick="TINY.box.show({html:'
Reason: '.$badge[reason].'
,animate:false,close:false,mask:false,boxid:
'success'
,autohide:2,top:-14,left:-17})
"><img src="
'.$badge[badge].'
" </a>');

请注意以单词Reason:开头的行。既然这不是你得到的错误,也许我猜错了,但毫无疑问你当前的代码太乱了。

我希望您在这里未显示的代码中清理您的输入($user$usr2[id])和存储的数据($badge[reason]),以防范cross-site scripting vulnerabilities和{ {3}}

答案 1 :(得分:1)

试试这个(固定开/关报价......我认为)

<?
    $badgesql = mysql_query("select * from usr_badge where user = '$user'");
    $user2 = mysql_query("select * from usr_users where username = '$user'");
    $usr2 = mysql_fetch_array($user2);
    $vipsql = mysql_query("select * from usr_vip where userid = '$usr2[id]'");
    $vipcheck = mysql_num_rows($vipsql);
    $badgecheck = mysql_num_rows($badgesql);
    $checkit = $badgecheck + $vipcheck;
    if($checkit==0) {
        echo("This user does not have any badges");

    } else {
        if($badgecheck!=0)
        {
            while($badge = mysql_fetch_array($badgesql))
            {
                echo('<a onclick="TINY.box.show({html: "Reason: '.$badge[reason].'",animate:false,close:false,mask:false,boxid:"success",autohide:2,top:-14,left:-17})"><img src="'.$badge[badge].'" /></a>');
            }
        }
        //Display VIP Badges
        if($vipcheck!=0)
        {
            $vipbadge = mysql_fetch_array($vipsql);
            $vip1 = mysql_query("select * from usr_vipdb where id = '$vipbadge[vipid]'");
            $vip2 = mysql_fetch_array($vip1);
            echo('<img src="'.$vip2[url].'" alt="This user is a VIP!" />');
        }
    }
?>