未定义的变量:详细信息在 C:\xampp\htdocs\redo\consultation.php 的第 21 行 Php

Undefined variable: details in C:\xampp\htdocs\redo\consultation.php on line 21 in Php

<?php include 'connection.php'; ?>
<?php
if (isset($_GET['consultation']))
{
    echo "Consultation Details";
    $no=$_GET['consultation'];
    ?>

    <form class="" method="get">
        <textarea name="details" rows="8" cols="80" placeholder="enter consultation details"></textarea><br>
        <button type="submit" name="c">submit</button>
    </form>

    <?php
    if (isset($_GET['details'])) {
        $details=$_GET['details'];
    }
    //$details= $_GET['details'];
    $insertQuery="INSERT INTO redo (consultation) VALUES ($details) WHERE no=$no;";
    $insert = mysqli_query($conn,$insertQuery);

    if ($insert) {
        echo "recorded";
        ?>
        <a href="display.php">Back to Total Patients</a>
        <a href="index.php">Back to Registration</a>
        <?php
    }
    else {
        echo "record couldnt be inserted";
    }
}
?>

$_GET['details'],您确定在表单中使用了 GET 方法吗?将 $_GET['details'] 更改为 $_REQUEST['details'].

准确地说,这个失败了:

if (isset($_GET['details'])) {
    $details=$_GET['details'];
}

我的意思是,if 条件不满足,所以 $details 没有定义,因为你没有在 if 之外的代码中的任何地方定义它。

其他解决方案是添加:

$details = '';

在那个if前面。