首页 > 解决方案 > 未定义变量:C:\xampp\htdocs\redo\consultation.php 中第 21 行 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";
    }
}
?>

标签: phpmysqli

解决方案


$_GET['details'],您确定您使用的GET是表单中的方法吗?更改$_GET['details']$_REQUEST['details']

确切地说,这个失败了:

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

我的意思是,if条件不满足,所以$details没有定义,因为你没有在if.

其他解决方案是添加:

$details = '';

在那之前if


推荐阅读