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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?