php - 注意 : Undefined index variable. PHP 脚本适用于 Linux 但不适用于 Windows

标签 php html linux web-deployment isset

我有一个适用于 Linux 但不适用于 Windows 的 PHP 脚本。 我可以接受我的 PHP 编码不是很好,我是新手。 我有一个表格,我将数据发布到它。现在它在 Windows 服务器上,我得到:

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

等等。

我尝试将所有变量声明为 0,并使用 isset,但它似乎不起作用。 也许我错误地使用了 isset。有人能帮我吗?

    <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 \n";
    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>

最佳答案

if(isset($_POST['nmr'], $_POST['UName'], ...) {
 $reg_wvar=$_POST['nmr'];
  $reg_UName=$_POST['UName'];
  ...
}

关于php - 注意 : Undefined index variable. PHP 脚本适用于 Linux 但不适用于 Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23389083/

相关文章:

php - 使用 PHP 简单 HTML DOM 解析器获取 Div 属性

javascript - 将 DOM 元素转换为原始 HTML 字符串

java - 从 Java 中的 Android Activity 写入/proc 文件系统

javascript - 我想在命令行上获取我的 linux 设备的准确经纬度。就像 HTML5 中的地理定位。我无权访问浏览器

php - Laravel 5.4 Cashier - 弥合文档方面的差距

php - 正则表达式中的反斜杠 - PHP

javascript - 更改 aud_play_pause() 中的图标

Linux shell 在串行计算中使用 disown

php - Linux Ubuntu PHP 版本在 CLI 和 PHPINFO() 中不同

php - 使用 session 名称创建一个 php 表