This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable,
visit the help center。
已关闭8年。
有人可以在下面的代码中解释为什么我收到此错误以及如何解决该错误,错误是指:
echo "<tr><td>{$r['logID']}</td><td><a href='viewuser.php?u={$r['>{$r['username']}</a> [{$r['userID']}]</td><td>{$r['amount']}</td><td><a href='5050.php?chal={$r['>Challenge</a></td><td>";
将其放在上下文中是整个代码段。
<?php
include "globals.php";
$minbet=1;
$maxg=10;
echo "<big>50 / 50 Crystals Game</big>";
function add_game()
{
global $ir,$t,$userid, $db, $minbet, $maxg;
if(!isset($_POST['amt']))
{
echo "<big>Adding a game</big>
<form action='5050.php?add=1' method='post'>
Amount of crystals:<input type='text' name='amt' size=10 maxlength=10>
<input type='submit' value='Add!'></form>
($maxg games max per user)
<a href='5050.php'>Back</a>";
}
else
{
$_POST['amt'] = abs((int) $_POST['amt']);
if($_POST['amt'] < $minbet)
{
echo "The minimum bet is $minbet
<a href='5050.php?add=1'>Back</a>";exit;
}
$theckcount=$db->query("SELECT logID FROM tchance WHERE userID={$ir['userid']} and active=1");
if($db->num_rows($theckcount) > ($maxg-1))
{
echo "There is a maximum of $maxg games per user.
<a href='5050.php'>Back</a>";exit;
}
if($ir['crystals'] < $_POST['amt'])
{
echo "You cannot afford that amount.
<a href='5050.php'>Back</a>";exit;
}
$db->query("UPDATE users SET crystals = crystals - {$_POST['amt']} WHERE userid = {$ir['userid']}");
$ir['crystals']=$ir['crystals'] - $_POST['amt'];
$db->query("INSERT INTO tchance VALUES ('', {$ir['userid']}, {$_POST['amt']}, 1)");
echo "Your game has been set. Good Luck.
<a href='5050.php'>Back</a>";
}
}
function view_games()
{
global $ir,$t,$userid, $db, $maxg;
$q=$db->query("SELECT t.*, u.username FROM tchance t left join users u on u.userid = t.userID WHERE t.active = 1 ORDER BY t.logID ASC");
echo "<a href='5050.php?add=1'>Add Game</a>
Table of users awaiting a challenge
<table class='table' width=50%><tr><th>Game ID</th><th>User</th><th>Amount</th><th>Challenge</th><th>Cancel</th></tr>";
if($db->num_rows($q) < 1){echo "<tr><td colspan=5>There are currenly no challenges</td></tr>";}
while($r=$db->fetch_row($q))
{
echo "<tr><td>{$r['logID']}</td><td><a href='viewuser.php?u={$r['>{$r['username']}</a> [{$r['userID']}]</td><td>{$r['amount']}</td><td><a href='5050.php?chal={$r['>Challenge</a></td><td>";
if($ir['userid']==$r['userID']){echo "<a href='5050.php?cancel={$r['>Cancel</a>";}
echo "</td></tr>";
}
echo "</table>";
}
function dogame()
{
global $ir,$t,$userid, $db;
$_GET['chal'] = abs((int) $_GET['chal']);
$q=$db->query("SELECT t.*, u.username from tchance t LEFT JOIN users u ON t.userID = u.userid Where t.logID={$_GET['chal']} AND t.active = 1 LIMIT 1");
if($db->num_rows($q) > 0)
{
$r=$db->fetch_row($q);
if($ir['crystals'] < $r['amount'])
{
echo "You cannot afford the challenge amount.
<a href='5050.php'>Back</a>";exit;
}
if($ir['userid'] == $r['userID'])
{
echo "You cannot accept your own challenge.
<a href='5050.php'>Back</a>";exit;
}
if(rand(1,2) == 1)
{
$winner=$r['userID']; $loser=$ir['userid'];
$winnername=$r['username'];
$losername=$ir['username'];
$tstring="Sorry, you Lost. Better luck next time.
<a href='5050.php'>Back</a>";
$db->query("UPDATE users SET crystals = crystals - {$r['amount']} WHERE userid={$ir['userid']}");
$db->query("UPDATE users SET crystals = crystals + ({$r['amount']} * 2) WHERE userid={$r['userID']}");
}
else
{
$winner=$ir['userid']; $loser=$r['userID'];
$winnername=$ir['username'];
$losername=$r['username'];
$tstring="You Won! Congratulations! You Won {$r['amount']} crystals.
<a href='5050.php'>Back</a>";
$db->query("UPDATE users SET crystals = crystals + {$r['amount']} WHERE userid={$ir['userid']}");
}
event_add($winner, "The game of {$r['amount']} crystals challenged by <a href='viewuser.php?u={$r['>{$r['username']}</a> was won by <a href='viewuser.php?u={$winner}'>{$winnername}</a>.", $t);
event_add($loser, "The game of {$r['amount']} crystals challenged by <a href='viewuser.php?u={$r['>{$r['username']}</a> was won by <a href='viewuser.php?u={$winner}'>{$winnername}</a>.", $t);
$db->query("UPDATE tchance SET active = 0 WHERE logID={$_GET['chal']}");
echo $tstring;
}
else
{
echo "This game has either been cancelled or someone played before you got the 5050.
<a href='5050.php'>Back</a>"; exit;
}
}
function cancel()
{
global $ir,$t,$userid, $db;
$_GET['cancel'] = abs((int) $_GET['cancel']);
$q=$db->query("SELECT * from tchance where logID={$_GET['cancel']} AND active = 1");
if($db->num_rows($q) > 0)
{
$r=$db->fetch_row($q);
$db->query("UPDATE users SET crystals = crystals + {$r['amount']} WHERE userid = {$ir['userid']}");
$ir['crystals']=$ir['crystals'] + $r['amount'];
$db->query("UPDATE tchance SET active = -1 WHERE logID = {$_GET['cancel']}");
echo "The game has been cancelled, and your crystals has been returned.
<a href='5050.php'>Back</a>";
}
else
{
echo "This game has already been canceled, does not exist, or someone already played.
<a href='5050.php'>Back</a>";
}
}
if(isset($_GET['cancel'])){cancel();}
elseif(isset($_GET['chal'])){dogame();}
elseif(isset($_GET['add'])){add_game();}
else{view_games();}
?>
感谢您抽出宝贵的时间来帮助我并教我。
echo "<tr><td>{$r['logID']}</td><td><a href='viewuser.php?u={$r['>{$r['username']}</a> [{$r['userID']}]</td><td>{$r['amount']}</td><td><a href='5050.php?chal={$r['>Challenge</a></td><td>";
您在双引号中间有“$ r [”。用斜杠将其转义,您会更好(PHP正在尝试评估您的变量)。您可能并不意味着拥有$ r,而只有r
echo "<tr><td>{$r['logID']}</td><td><a href='viewuser.php?u={\$r['>{$r['username']}</a> [{$r['userID']}]</td><td>{$r['amount']}</td><td><a href='5050.php?chal={$r['>Challenge</a></td><td>";
我个人认为您的语法令人困惑,我宁愿使用“。”连接字符串和变量:
echo ' <tr><td>'
. $r['logID']
. '</td><td>'
. '<a href="viewuser.php?u=r[' . $r['username'] .']">'.$r['username'].'</a>'
. '['.$r['userID'].']</td><td>'
. $r['amount'] . '</td><td>'
. '<a href="5050.php?chal=r">Challenge</a></td><td>';
我是一名优秀的程序员,十分优秀!