未定义的数组键并且不知道该键来自哪里

undefined array key and don't know where that key comes from

我正在关注这个, https://www.androidhire.com/insert-data-from-app-to-mysql-android/

步骤'Upload the php script on your server'有错误, 'code for get_data.php file'

<?php

include 'DatabaseConfig.php' ;
 
 $con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
 
 
     $room = $_POST['room'];
     $time = $_POST['time'];


 $Sql_Query = "insert into GetDataTable (room,time) values ('$room','$time')";
 
 if(mysqli_query($con,$Sql_Query)){
 
 echo 'Data Submit Successfully';
 
 }
 else{
 
 echo 'Try Again';
 
 }
 mysqli_close($con);
?>

这是我的代码和我的数据库table是这个 enter image description here

错误信息是 警告:第 8 行

中 C:\xampp\htdocs\get_data.php 中未定义的数组键“room”

所以我试过了

if(isset($_POST['room']){
        $room = $_POST['room'];
    }

但这给了我 警告:未定义的变量,

您需要将 if() 放在使用 $room:

的整个代码块周围
<?php

include 'DatabaseConfig.php' ;
 
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
 
if ( isset( $_POST['room'] ) ) {
   $room = $_POST['room'];
   $time = $_POST['time'];

   $Sql_Query = "insert into GetDataTable (room,time) values ('$room','$time')";
 
   if(mysqli_query($con,$Sql_Query)){
       echo 'Data Submit Successfully';
   } else{
       echo 'Try Again';
   }
   mysqli_close($con);
}
?>