0
我想從下拉菜單中刪除會話。用戶將從下拉菜單中選擇一個會話,然後點擊刪除按鈕,這應該刪除數據庫中的會話。問題是,如果我點擊刪除按鈕,它會出現一個未定義的索引錯誤,說明sessionsDrop
未在200行中定義我的問題是:嘗試從下拉菜單中刪除會話時發生未定義索引錯誤
1:如何擺脫未定義的代碼索引錯誤2:如何以及在哪裏編寫if語句,以便如果刪除成功,則會回顯「Session ... was Deleted」,否則如果未刪除則顯示回顯「發生錯誤,會話。 ..沒有刪除」
下面是代碼:
$sessionnum = 0;
if (isset($_POST['modulesubmit'])) {
if($_REQUEST['modulesDrop']==''){
echo "Please Select a Module from the Drop Down Menu Above";
}
else{
var_dump($_POST['modulesDrop']);
$sessionquery = "
SELECT SessionId, SessionDate, SessionTime, ModuleId
FROM Session
WHERE
(ModuleId = ?)
ORDER BY SessionDate, SessionTime
";
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("s",$_POST['modulesDrop']);
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId);
$sessionqrystmt->store_result();
$sessionnum = $sessionqrystmt->num_rows();
$dataArraySession = array();
while ($sessionqrystmt->fetch()) {
$dataArraySession[$dbSessionId]['SessionDate'] = $dbSessionDate;
$dataArraySession[$dbSessionId]['SessionTime'] = $dbSessionTime;
}
$sessionHTML = "";
$sessionHTML .= '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;
foreach ($dataArraySession as $sessionId => $sessionData) {
$sessionHTML .= "<option value='$sessionId'>" . $sessionId . " - " . $sessionData['SessionDate']. " - " . $sessionData['SessionTime'] ."</option>".PHP_EOL;
}
$sessionHTML .= '</select>';
}
if ($sessionnum > 0) {
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Sessions: <?php echo $sessionHTML; ?><input id="sessionSubmit" type="submit" value="Delete" name="sessionsubmit" /></p>
</form>
<?php
}
else {
echo "<p>Sorry, You have No Sessions under this Module</p>";
}
}
if (isset($_POST['sessionsubmit'])) {
if($_REQUEST['sessionsDrop']==''){ //line 200 where undefined index occurs
echo "Please Select a Session from the Drop Down Menu Above to Delete a Session";
}
else{
var_dump($_POST['sessionsDrop']);
$sessiondel = $_POST['sessionsDrop'];
$sessiondeletesql = " DELETE sess
FROM Session AS sess
WHERE sess.SessionId = ?";
if (!$delete = $mysqli->prepare($sessiondeletesql)) {
// Handle errors with prepare operation here
}
//Dont pass data directly to bind_param store it in a variable
$delete->bind_param("s", $sessiondel);
$delete->execute();
if ($delete->errno) {
// Handle query error here
}
$delete->close();
echo "Session $sessiondel was Deleted";
}
}
?>