我正在學習如何向站點添加論壇部分的教程,用戶可以在其中發表評論,然后使用PHP和編輯它們MySQL。在數據庫中發布評論絕對沒問題,但是當我點擊編輯時,$message = $_POST['message'];當我在頁面上(也不是在文本框中)回顯時不會打印出來,并且我收到錯誤消息Undefined index: message。請有人闡明我對未進入頁面的消息的實際內容做錯了什么edit-comments.php。論壇.php: <?php require 'header.php'; date_default_timezone_set('Europe/London'); include 'comments.php'; $studentID = $_SESSION['studentID']; echo "<form method='POST' action='".setComments($conn)."'> <input type='hidden' name='studentID' value='".$studentID."'> <input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'> <textarea class='cmtBox' name='message'></textarea> <br> <button class='btnCmtBox' type='submit' name='cmt-submit'>Comment</button> </textarea> </form> "; getComments($conn); ?>評論.php:<?php function setComments($conn) { if(isset($_POST['cmt-submit'])){ $message = $_POST['message']; $date = $_POST['date']; $studentID = $_POST['studentID']; $sql = "INSERT INTO `comment` (`message`, `date`, `studentID`) VALUES ('$message', '$date', '$studentID') "; $result = $conn->query($sql); // $stmt = $conn->prepare ("INSERT INTO `comment` (`message`, `date`, `studentID`) VALUES (?, ?, ?) "); // $stmt->bind_param("iii", $comment, $date, $username); // $stmt->execute(); // $result = $stmt->get_result(); } } function getComments($conn) { $sql = "SELECT `comment`.`message`, `comment`.`date`, `student`.`studentID`, `student`.`username` FROM `comment` INNER JOIN `student` ON `comment`.`studentID` = `student`.`studentID`"; $result = $conn->query($sql); while ($row = $result->fetch_assoc()) { echo "<div class='cmt-box'><p>"; echo $row['studentID']."<br>"; echo $row['username']."<br>"; echo $row['date']."<br>"; echo nl2br($row['message']); echo "</p>
1 回答

慕森卡
TA貢獻1806條經驗 獲得超8個贊
您在 comments.php 的下面一行中給出了 input name
=text
而不是message
<input type='hidden' name='text' value='".$row['message']."'>
正確的代碼是
<input type='hidden' name='message' value='".$row['message']."'>
- 1 回答
- 0 關注
- 113 瀏覽
添加回答
舉報
0/150
提交
取消