有人可以解释为什么我在下面的代码中收到此错误以及我可以采取哪些措施来修复它,错误指的是: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();}
?>
感谢您抽出宝贵时间帮助我并教我。
答案 0 :(得分:2)
你忘了关闭数组:
?chal={$r['>Challenge</a></td><td>
答案 1 :(得分:2)
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>';
答案 2 :(得分:0)
你的回声中还有许多未转义的双引号,这导致了另一个错误。看看你能不能找到它们!这是一个很好的做法。
我还建议您在过度使用双引号时使用单引号,反之亦然。