dta38159 2014-04-30 13:12
浏览 73
已采纳

注意:未定义的索引变量。 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>
  • 写回答

1条回答 默认 最新

  • douhao1956 2014-04-30 13:26
    关注
    if(isset($_POST['nmr'], $_POST['UName'], ...) {
     $reg_wvar=$_POST['nmr'];
      $reg_UName=$_POST['UName'];
      ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺