这个PHP通知是什么意思?

<?php
    $username="xxx";
    $password="xxx";
    $database="mobile_app";

    mysql_connect('localhost',$username,$password);

    @mysql_select_db($database) or die( "Unable to select database");

    foreach (array('courseid','roomChosen') as $varname) {
        $$varname = (isset($_POST[$varname])) ? $_POST[$varname] : '';
    }

    if (isset($_POST['prequestion'])) {
        $roomquery = "
                     SELECT Room
                     FROM Room
                     WHERE
                     (Room = '".mysql_real_escape_string($roomChosen)."')
                     ";

        $roomnum = mysql_num_rows($roomresult = mysql_query($roomquery));
        mysql_close();

        if($roomnum ==0){
            $msg = "This Room is Invalid '$roomChosen'";
        } 
        else {
            $msg = "This Room is Valid '$roomChosen'";
        }
    }
    $d = array("msg" => $msg);
    echo json_encode($d);
?>

In this line of code near the bottom:

$d = array("msg" => $msg);

I am getting this notice:

Notice: Undefined variable: msg in /u08877587/Mobile_app/room2.php on line 46 {"msg":null}

How do I fix this notice?

You should place $d = array("msg" =>$msg) inside if(isset($_POST['prequestion'])) { }

I.e:

if (isset($_POST['prequestion'])) 
{
    if($roomnum ==0)
    {
        $msg = "This Room is Invalid '$roomChosen'";
    } 
    else 
    {            
        $msg = "This Room is Valid '$roomChosen'";
    }


   $d = array("msg" => $msg);
   echo json_encode($d);    
}

In some error_reporting modes, PHP will give you a heads-up if you use a variable that hasn't been defined. You can do:

if(isset($msg) {
  $d = array("msg" => $msg);
}

or:

$d = array("msg" => @$msg);

or adjust your error_reporting configuration to not pass along E_NOTICE messages. There are times where this notice will help you find that you've done something like misspelled a variable, though.

You are never entering the if (isset($_POST['prequestion'])) block, and so $msg is not being set. If that is a bug, try fixing that to solve your problems. Otherwise, you can do:

if ($msg) {
  $d = array("msg" => $msg);
}

Which will make sure $msg exists before you are trying to use it. Either that or set $msg to an empty string or something before the if (isset($_POST['prequestion'])) statement.