注意:未定义的索引变量。 PHP脚本适用于Linux但不适用于Windows

I have a PHP script that works on Linux but not on Windows. I can accept that my PHP coding isn't that great, I'm a newbie. I have a form, and I post the data to it. Now that it is on a Windows server, I get:

Notice: Undefined index: nmr in C:\Apache24\htdocs\index.php on line 31 ...

and so on.

I tried declaring all the variables as 0, and using isset, but it doesn't seem to work. Perhaps I'm using isset wrong. Can someone help me?

    <html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="http://www.hackmaine.org/favicon.ico">
<link rel="stylesheet" type="text/css" href="sty.css">
    <title>NMR Scheduler</title>
</head>
<body>

<?PHP
$Unity = 'unchecked';
$Inova = 'unchecked';
$Experiment = $duration = $ToD = $startTime = $ddate = $nmr = $UName = 0;

if (isset($_POST['Submit1']))
{
    $selected_radio = $_POST['nmr'];
    switch ($selected_radio) 
    {
        case Unity:
            break;
        case Inova:
            break;
        default:
        echo "Select an NMR";
    }
}

isset($Experiment, $duration, $ToD, $startTime, $ddate, $UName);    

    $reg_wvar=$_POST['nmr'];
    $reg_UName=$_POST['UName'];
    $reg_Date=$_POST['ddate'];
    $reg_startTime=$_POST['startTime'];
    $reg_ToD=$_POST['ToD'];
    $reg_duration=$_POST['duration'];
    $reg_Experiment=$_POST['Experiment'];

    $stringy = "$reg_wvar, $reg_UName, $reg_Date, $reg_startTime $reg_ToD,  $reg_duration, $reg_Experiment 
";
    echo $stringy;
    $filename = 'newEntry.txt';
// Let's make sure the file exists and is writeable first.
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
    }
    // Write $somecontent to our opened file.
    if (fwrite($handle, $stringy) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
//echo "Success, wrote ($somecontent) to file ($filename)";
    fclose($handle);
    } else {
    echo "Data not written, Make Sure you selected an NMR";
}
?>

<center>
<FORM ACTION="if.php" method="post">
<h2>NMR Usage Scheduler</h2>
<br /><br />
<INPUT TYPE = 'Radio' Name ='nmr'  value= 'Unity'>Unity
<INPUT TYPE = 'Radio' Name ='nmr'  value= 'Inova' >Inova<br /><br />
<B>Your Name :</B><input type="text" size="20" maxlength="10" name="UName" required><br /><br />
<B>Enter Date (mm/dd):</B> <input type="text" size="20" maxlength="5" name="ddate"  required><br /><br />
<B>Start Time (hh:mm):</B> <input type="text" size="8" maxlength="5" name="startTime"  required>
<INPUT TYPE = 'Radio' Name ='ToD'  value= 'AM' >AM
<INPUT TYPE = 'Radio' Name ='ToD'  value= 'PM' checked>PM
<br /><br />
<B>Duration:  </B> <input type="text" size="20" maxlength="5" name="duration"  required><br /><br />
<B>Experiment:</B> <input type="text" size="20" maxlength="5" name="Experiment" required><br /><br />
<INPUT TYPE = "Submit" Name = "Submit1"  VALUE = "Submit">
</FORM>
</center>


</body>
</html>
查看全部
dta38159
dta38159
2014/04/30 13:12
  • linux
  • php
  • html
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复