亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未定義的索引:PHP 腳本中的消息

未定義的索引:PHP 腳本中的消息

PHP
qq_花開花謝_0 2022-12-23 14:25:42
我正在學習如何向站點添加論壇部分的教程,用戶可以在其中發表評論,然后使用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']."'>


查看完整回答
反對 回復 2022-12-23
  • 1 回答
  • 0 關注
  • 113 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號