我正在尝试编辑名为'minutes'的数据库表中的字段,有几组分钟,但代码工作如下...会话开始设置当前用户在下面的查询中使用(currentUser = Bnumber)...当在'viewstudentminutes.php'页面上点击编辑按钮时,它会抛出以下错误'注意:第179行的viewstudentminutes.php中的未定义索引:Minute_ID
致命错误:带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:1064 SQL语法中有错误;检查与MySQL服务器版本相对应的手册,以便在viewstudentminutes.php中使用“第1行”附近的正确语法:179堆栈跟踪:#0 viewstudentminutes.php(179):PDO-> prepare('SELECT * FROM'...')在第179行的viewstudentminutes.php中抛出#1 {main}
以下是在minute.php页面上的所有代码,下面是'viewstudentminutes.php'中的代码
<?php
include ("dbConnect.php");
include ("studenthead.php");
session_start();
if (!(isset($_SESSION["sess_username"]))) header ("Location: index.php");
$currentUser=$_SESSION["sess_username"];
if (isset($_POST['addMinute'])) {
$newB_number = $currentUser;
$newDate = $_POST['Date'];
$newTime = $_POST['Time'];
$newDiscussion = $_POST['Discussion'];
$newActions = $_POST['Actions'];
$newDateofnextmeeting = $_POST['Dateofnextmeeting'];
$newStatus = "Submitted";
$newE_number = $_POST['E_number'];
$newSupervisor_comments = $_POST['Supervisor_comments'];
$dbQuery = $db->prepare("insert into minute values (null, :newB_number, :newDate, :newTime, :newDiscussion, :newActions, :newDateofnextmeeting, :newStatus, :newE_number, :newSupervisor_comments )");
$dbParams = array('newB_number'=>$newB_number, 'newDate'=>$newDate, 'newTime'=>$newTime, 'newDiscussion'=>$newDiscussion, 'newActions'=>$newActions, 'newDateofnextmeeting'=>$newDateofnextmeeting, 'newStatus'=>$newStatus, 'newE_number'=>$newE_number, 'newSupervisor_comments'=>$newSupervisor_comments);
$dbQuery->execute($dbParams);
$lastInserted = $db->lastInsertId();
}
if (isset($_POST['deleteMinuteID'])) {
$ID = $_POST['deleteMinuteID'];
$dbQuery = $db->prepare("delete from minute where ID=:ID");
$dbParams = array('ID'=>$ID);
$dbQuery->execute($dbParams);
}
if (isset($_POST['editCommitID'])) {
$ID = $_POST['editCommitID'];
$editB_number = $_POST['editB_number'];
$editDate = $_POST['editDate'];
$editTime = $_POST['editTime'];
$editDiscussion = $_POST['editDiscussion'];
$editActions = $_POST['editActions'];
$editDateofnextmeeting = $_POST['editDateofnextmeeting'];
$editStatus = $_POST['editStatus'];
$editE_number = $_POST['editE_number'];
$editSupervisor_comments = $_POST['editSupervisor_comments'];
$dbQuery = $db->prepare("update minute set B_number=:B_number, Date=:Date, Time=:Time, Discussion=:Discussion, Actions=:Actions, Dateofnextmeeting=:Dateofnextmeeting, Status=:Status, E_number=:E_number, Supervisor_comments=:Supervisor_comments where ID=:ID");
$dbParams = array('ID'=>$ID, 'B_number'=>$editB_number, 'Date'=>$editDate, 'Time'=>$editTime, 'Discussion'=>$editDiscussion, 'Actions'=>$editActions, 'Dateofnextmeeting'=>$editDateofnextmeeting, 'Status'=>$editStatus, 'E_number'=>$editE_number, 'Supervisor_comments'=>$editSupervisor_comments);
$dbQuery->execute($dbParams);
header("location: minutes.php");
exit();
}
?>
<html>
<head>
<title>Minutes</title>
<h2>Minutes</h2>
<table class="table table-striped">
<thead>
<th>B Number</th><th>Date</th><th>Time</th><th>Discussion</th> <th>Actions</th><th>Date of next meeting</th><th>Status</th><th>Supervisor</th><th>Supervisor comments</th>
</thead>
<tbody>
<?php
$dbQuery = $db->prepare("select * from minute where '$currentUser'=B_number ");
$dbQuery->execute();
$numMinutes = $dbQuery->rowCount();
echo "<p>There are $numMinutes sets of minutes in the system</p>";
$oddRow=true;
while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
$ID = $dbRow['ID'];
$B_number = $dbRow['B_number'];
$Date = $dbRow['Date'];
$Time = $dbRow['Time'];
$Discussion = $dbRow['Discussion'];
$Actions = $dbRow['Actions'];
$Dateofnextmeeting = $dbRow['Dateofnextmeeting'];
$Status = $dbRow['Status'];
$E_number = $dbRow['E_number'];
$Supervisor_comments = $dbRow['Supervisor_comments'];
if ($oddRow) $rowClass="odd"; else $rowClass="even";
$oddRow=!$oddRow;
if (isset($_POST['editMinuteID']) && $_POST['editMinuteID']==$ID) {
echo "<tr class='$rowClass '>
<form style='display:inline' method='post' action='minutes.php'>
<input type='hidden' name='editCommitID' value='$ID'>
<td><input type='varchar' name='editB_number' value='$B_number'></td>
<td><input type='date' name='editDate' value='$Date'></td>
<td><input type='time' name='editTime' value='$Time'></td>
<td><input type='text' name='editDiscussion' value='$Discussion'></td>
<td><input type='text' name='editActions' value='$Actions'></td>
<td><input type='date' name='editDateofnextmeeting' value='$Dateofnextmeeting'></td>
<td><input type='enum' name='editStatus' value='$Status'></td>
<td><input type='varchar' name='editE_number' value='$E_number'></td>
<td><input type='text' name='editSupervisor_comments' value='$Supervisor_comments'></td>
<td colspan='2'><input type='image' src='edit.png'>
</form>
</tr>";
} else {
echo "<tr class='$rowClass'><td>$B_number</td><td>$Date</td><td>$Time</td><td>$Discussion</td><td>$Actions</td><td>$Dateofnextmeeting</td><td>$Status</td><td>$E_number</td><td>$Supervisor_comments</td>
<td class='operation'>
<form class='display:inline' method='post' action='viewstudentminutes.php'>
<input type='hidden' name='editMinute_ID' value='$ID'>
<input type='image' src='edit.png' style='padding-top:7px'>
</form></td>
<td class='operation'>
<form class='display:inline' method='post' action='minutes.php'
onsubmit='return confirm(\"Are you sure?\")'>
<input type='hidden' name='deleteMinuteID' value='$ID'>
<input type='image' src='delete.png' style='padding-top:7px'>
</form></td>
<td class='operation'>
<form class='display:inline' method='post' action='viewstudentminutes.php' onsubmit='viewstudentminutes.php'>
<input type='image' src='view.png' style='padding-top:7px'>
<input type='hidden' name='Minute_ID' value='" . $ID . "'>
</form></td>
</tr>";
}
}
?>
以及'viewstudentminutes'中的相应代码
<?php
include ("dbConnect.php");
include ("studenthead.php");
session_start();
if (!(isset($_SESSION["sess_username"]))) header ("Location: index.php");
$currentUser=$_SESSION["sess_username"];
if (isset($_POST['addMinute'])) {
$newB_number = $currentUser;
$newDate = $_POST['Date'];
$newTime = $_POST['Time'];
$newDiscussion = $_POST['Discussion'];
$newActions = $_POST['Actions'];
$newDateofnextmeeting = $_POST['Dateofnextmeeting'];
$newStatus = "Submitted";
$newE_number = $_POST['E_number'];
$newSupervisor_comments = " ";
$dbQuery = $db->prepare("insert into minute values (null, :newB_number, :newDate, :newTime, :newDiscussion, :newActions, :newDateofnextmeeting, :newStatus, :newE_number, :newSupervisor_comments )");
$dbParams = array('$newB_number'=>$newB_number, 'newDate'=>$newDate, 'newTime'=>$newTime, 'newDiscussion'=>$newDiscussion, 'newActions'=>$newActions, 'newDateofnextmeeting'=>$newDateofnextmeeting, 'newStatus'=>$newStatus, 'newE_number'=>$newE_number, 'newSupervisor_comments'=>$newSupervisor_comments);
$dbQuery->execute($dbParams);
$lastInserted = $db->lastInsertId();
}
if (isset($_POST['editCommitID'])) {
$ID = $_POST['editCommitID'];
$editB_number = $_POST['editB_number'];
$editDate = $_POST['editDate'];
$editTime = $_POST['editTime'];
$editDiscussion = $_POST['editDiscussion'];
$editActions = $_POST['editActions'];
$editDateofnextmeeting = $_POST['editDateofnextmeeting'];
$editStatus = $_POST['editStatus'];
$editE_number = $_POST['editE_number'];
$editSupervisor_comments = $_POST['editSupervisor_comments'];
$dbQuery = $db->prepare("update minute set B_number=:B_number, Date=:Date, Time=:Time, Discussion=:Discussion, Actions=:Actions, Dateofnextmeeting=:Dateofnextmeeting, Status=:Status, E_number=:E_number, Supervisor_comments=:Supervisor_comments where ID=:ID");
$dbParams = array('ID'=>$ID, 'B_number'=>$editB_number, 'Date'=>$editDate, 'Time'=>$editTime, 'Discussion'=>$editDiscussion, 'Actions'=>$editActions, 'Dateofnextmeeting'=>$editDateofnextmeeting, 'Status'=>$editStatus, 'E_number'=>$editE_number, 'Supervisor_comments'=>$editSupervisor_comments);
$dbQuery->execute($dbParams);
header("location: viewstudentminutes.php");
exit();
}
?>
<html>
<head>
<title>Minutes</title>
<h2>Minutes</h2>
<table class="table table-condensed">
<?php
$dbQuery= $db->prepare("SELECT * FROM `Minute` WHERE `B_number` = '" . $currentUser . "' AND `id` = " . $_POST['Minute_ID']);
$dbQuery->execute();
$oddRow=true;
while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
$ID = $dbRow['ID'];
$B_number = $dbRow['B_number'];
$Date = $dbRow['Date'];
$Time = $dbRow['Time'];
$Discussion = $dbRow['Discussion'];
$Actions = $dbRow['Actions'];
$Dateofnextmeeting = $dbRow['Dateofnextmeeting'];
$Status = $dbRow['Status'];
$E_number = $dbRow['E_number'];
$Supervisor_comments = $dbRow['Supervisor_comments'];
if ($oddRow) $rowClass="odd"; else $rowClass="even";
$oddRow=!$oddRow;
if (isset($_POST['editMinuteID']) && $_POST['editMinuteID']==$id) {
echo "<tr class='$rowClass'>
<form style='display:inline' method='post' action='viewstudentminutes.php'>
<input type='hidden' name='editCommitID' value='$ID'>
<tr><td colspan='2'><input type='image' src='edit.png'></tr>
<tr><th>BNumber</th><td><input type='varchar' name='editB_number' value='$B_number'></td></tr>
<tr><th>Date</th><td><input type='date' name='editDate' value='$Date'></td></tr>
<tr><th>Time</th><td><input type='time' name='editTime' value='$Time'></td></tr>
<tr><th>Discussion</th><td><input type='text' name='editDiscussion' value='$Discussion'></td></tr>
<tr><th>Actions</th><td><input type='text' name='editActions' value='$Actions'></td></tr>
<tr><th>Date of Next Meeting</th><td><input type='date' name='editDateofnextmeeting' value='$Dateofnextmeeting'></td></tr>
<tr><th>Status</th><td><input type='enum' name='editStatus' value='$Status'></td></tr>
<tr><th>E Number</th><td><input type='varchar' name='editE_number' value='$E_number'></td></tr>
<tr><th>Supervisor Comments</th><td><input type='text' name='editSupervisor_comments' value='$Supervisor_comments'></td></tr>
</form>
</tr>";
} else {
echo "<tr class='$rowClass'>
<td class='operation'>
<form class='display:inline' method='post' action='viewstudentminutes.php'>
<input type='hidden' name='editMinute_ID' value='$ID'>
<input type='image' src='edit.png' style='padding-top:7px'>
</form></td>
<tr><th>BNumber</th><td>$B_number</td></tr>
<tr><th>Date</th><td>$Date</td></tr>
<tr><th>Time</th><td>$Time</td></tr>
<tr><th>Discussion</th><td>$Discussion</td></tr>
<tr><th>Actions</th><td>$Actions</td></tr>
<tr><th>Date of Next Meeting</th><td>$Dateofnextmeeting</td></tr>
<tr><th>Status</th><td>$Status</td></tr>
<tr><th>E Number</th><td>$E_number</td></tr>
<tr><th>Supervisor Comments</th> <td>$Supervisor_comments</td></tr>
</tr>";
}
}
?>
</table>
答案 0 :(得分:0)
您应该按如下方式编辑查询行:
$dbQuery= $db->prepare("SELECT * FROM `Minute` WHERE `B_number` = '" . $currentUser . "' AND `id` = " . $_POST['editMinute_ID']);