-2
在我的應用程序中,我試圖返回到每個MySQL行。除此之外,當我試圖這樣做,我得到的錯誤:PDO和Foreach(非法字符串偏移)
[週五17年10月9日:03:56.314003 2015年] [:錯誤] [PID 10641] [客戶127.0.0.1:40897] PHP的警告:第79行/var/www/html/ViewTicket.php中的非法字符串偏移量'Date',referer:http://localhost/Support
[Fri Oct 09 17:03:56.314041 2015] [:error] [pid 10641] [client 127.0 .0.1:40897] PHP的警告:非法串在/var/www/html/ViewTicket.php偏移 '內容' 上線84,引用者:http://localhost/Support
這裏是我的編碼:
<?php
$pageT = "View Ticket";
require_once("core/inc.php");
$ID = strip_tags(htmlentities($_GET['ID']));
$db = new DB();
$Config = new Config;
$User = new User;
$Organize = new Organize;
$Ticket = $db->fetchRow(
'SELECT * FROM tickets WHERE ID = :id',
[':id' => $ID]
);
$TR = $db->fetchRow(
'SELECT * FROM ticket_replies WHERE TID = :tid',
[':tid' => $ID]
);
$Poster = $db->fetchRow(
'SELECT * FROM users WHERE UID = :poster',
[':poster' => $Ticket['Poster']]
);
$Replier = $db->fetchRow(
'SELECT * FROM users WHERE UID = :poster',
[':poster' => $TR['Poster']]
);
if($Ticket == 0) {
echo "Sorry, but this is an unkown ticket.";
require_once("modules/design/footer.ris.php");
die();
}
/*
if($User->Info('UID') !== $Ticket['Poster']) {
if($User->Info('Rank') !== "Support" || $User->Info('Rank') !== "Admin" || $User->Info('Rank') !== "Admin") {
echo "Nice try, this is not your ticket. ;(";
require_once("modules/design/footer.ris.php");
die();
}
}
*/
echo '
<div class="row">
<div class="col-md-8 col-lg-9">
<div class="panel panel-default m-t-20">
<div class="panel-heading">
<h3 class="panel-title">
<span class="label label-warning"> '.strip_tags(htmlentities($Ticket['Priority'])).'</span>
<span class="label label-primary"> '.strip_tags(htmlentities($Ticket['Dept'])).'</span> '.strip_tags(htmlentities($Ticket['Title'])).''; if($User->Info('Rank') == "Admin" || $User->Info('Rank') == "Owner") { echo "<a style='float:right;margin-left:5px;'class='btn btn-icon waves-effect waves-light btn-danger m-b-5' href=''>Delete Ticket</a> <a style='float:right;margin-left:5px;'class='btn btn-icon waves-effect waves-light btn-info m-b-5' href=''>View Logs</a> <a style='float:right;' class='btn btn-icon waves-effect waves-light btn-info m-b-5' href='AP_EditUser?UID=".$Poster['UID']."'>Edit User</a> "; } echo '</h3>
</div>
<div class="panel-body">
<div class="media m-b-30">
<div class="media-body"><span class="media-meta pull-right">'.strip_tags(htmlentities($Organize->timeElapsedFromUNIX($Ticket['Date']))).'</span>
<h4 class="text-primary m-0"><u>'.strip_tags(htmlentities($Poster['Username'])).'</u></h4>
</div>
</div>
<p>
'.strip_tags(htmlentities($Ticket['Details'])).'
</p>
</div>
</div>
';
foreach ($TR as $Reply) {
if($Replier['Rank'] == "Support" || $Replier['Rank'] == "Admin" || $Replier['Rank'] == "Owner") {
echo '
<div style="border-top:4px solid red;" class="panel panel-default m-t-20">
<div class="panel-body">
<div class="media m-b-30">
<div class="media-body"><span class="media-meta pull-right">'.strip_tags(htmlentities($Organize->timeElapsedFromUNIX($Reply['Date']))).'</span>
<h4 class="text-primary m-0">'.strip_tags(htmlentities($Replier['Username'])).'</h4> <small>'.$Replier['Rank'].'</small>
</div>
</div>
<p>
'.$Organize->showBBcodes($Reply['Content']).'
</p>
</div>
</div>
';
} else {
echo '
<div style="border-top:4px solid #CCC;" class="panel panel-default m-t-20">
<div class="panel-body">
<div class="media m-b-30">
<div class="media-body"><span class="media-meta pull-right">'.strip_tags(htmlentities($Organize->timeElapsedFromUNIX($TR['Date']))).'</span>
<h4 class="text-primary m-0">'.strip_tags(htmlentities($Replier['Username'])).'</h4> <small>'.$Replier['Rank'].'</small>
</div>
</div>
<p>
'.strip_tags(htmlentities($Reply['Details'])).'
</p>
</div>
</div>
';
}
break;
}
echo '
<div class="panel panel-default">
<div class="panel-body">
<div class="media">
<form role="form" method="POST">
<div class="media-body">
<textarea class="wysihtml5 form-control" id="replyDetails" name="replyDetails" rows="9" placeholder="Reply here..."></textarea>
</div>
</div>
<div class="text-right">
<button type="submit" id="addReply" name="addReply" class="btn btn-primary waves-effect waves-light m-t-30 w-md">Send Reply</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
';
if(isset($_POST['addReply'])) {
$Details = strip_tags(htmlentities($_POST['replyDetails']));
if(empty($Details)) {
echo '<div class="col-md-8"><div class="alert alert-danger"><strong>Could not send reply :</strong> <br /> • You forgot a field or two. Please try again.</div></div>';
} elseif(strlen($Details) > 700) {
echo '<div class="col-md-8"><div class="alert alert-danger"><strong>Could not send reply :</strong> <br /> • You cannot exeed 700 characters. Please try again.</div></div>';
} else {
$Values = [
'TID' => $ID,
'Poster' => $User->Info('UID'),
'Content' => $Details,
'Date' => time()
];
$insertValues = $db->insert('ticket_replies')->values($Values);
$Values2 = [
'Username' => $User->Info('Username'),
'UID' => $User->Info('UID'),
'IP' => $Logs->IP(),
'Platform' => $Logs->Browser(),
'Type' => '8',
'Value' => 'Replied to a ticket.',
'Date' => $Logs->Date(),
];
$insertValues2 = $db->insert('logs')->values($Values2);
}
}
要跟上面的錯誤,它不輸出任何錯誤只是返回'1'。
我可能會說,' 'SELECT * FROM ticket_replies WHERE TID =:TID','此查詢沒有返回稱爲'Content'任何領域。請做'print_r($ TR):exit;'並在這裏傳遞結果。 – mloureiro
對不起,我收到 'array(5){[「ID」] => string(1)「1」[「TID」] => string(1)「1」[「Poster」] =>字符串(1)「1」[「Content」] =>字符串(23)「測試內容,kthx ily。」 [「Date」] => string(10)「1444357123」}' – Varian
但這只是一個元素?是'print_r($ TR)'或'print_r($回覆)' – mloureiro