XAMPP的非特定错误
我知道XAMPP在Win 7上有很多问题。所以我成功安装了它,现在我有了一些我从未有过的非特定错误。XAMPP的非特定错误
我在HTML
<form method="post" action="site.php">
<input type="text" name="NAME">
</form>
简单 - 标签和我的PHP代码也只是简单:
<?php
$something = $_POST['NAME'];
?>
当我开始XAMPP并在 “htdocs目录” 打开该HTML有问题/注意事项:
说明:未定义指数:WERT在C:\ XAMPP \ htdocs中\上线test.php的40
这只是一个XAMPP错误?因为我以前从未遇到过这个问题,所以看起来很安静。我使用XAMPP 1.7.7。
问候:)
的“未定义指数”通知弹出,当您使用尚未设置直到那时数组索引值:
<?php
$myarray = array('a'=>1, 'b'=>2);
var_dump($myarray['a']); //outputs int(1) as this is defined
var_dump($myarray['c']); //we defined 'a' and 'b' but not 'c'.
?>
第三行会给:“通知:未定义指数:C在第3行C:\ xampp \ htdocs \ test.php“。
这是通常发生在访问$ _GET或$ _POST数组时。大多数情况下,原因是您拼错了索引(例如,您输入了$_POST['tset']
而不是$_POST['test']
),或者因为您在提交信息的HTML表单中编辑了<input>
元素,然后忘记重新调整PHP代码。
您可以通过是否存在索引使用isset()
像这样的测试以确保一切工作正常:
if(isset($_POST['test'])) {
$myvar = $_POST['test'];
//and then whatever else you intended
}
else {
//the index wasn't defined - you made a mistake, or possibly the user deliberately removed an input from the submitting form
$error = "POST-array is missing the index 'test'!";
//and now make sure that things after this which rely on the 'test' value don't run
}
一个非常普遍的线,你将在脚本的很多发现:
$myvar = isset($_POST['test']) ? $_POST['test'] : 'N/A';
这使用if-else结构的特殊PHP速记。这条线几乎完全一样:
if(isset($_POST['test'])) {
$myvar = $_POST['test'];
}
else {
$myvar = 'N/A';
}
谢谢;)我的问题现在解决了。 – 2012-04-17 18:20:32
你应该这样做:
<?php
if(isset($_POST['NAME'])){
$something = $_POST['NAME'];
}
?>
当您打开一个页面,没有$_POST['NAME']
,直到你提交的数据。
我猜想变量的名称已经改变了。 – 2012-04-17 18:04:48
为什么安装XAMPP? – elboletaire 2012-04-17 17:59:52
你确定它是正确的脚本,它说第40行... – thumbmunkeys 2012-04-17 18:01:30
可能重复[PHP $ _GET和$ _POST未定义问题](http://*.com/questions/1359240/php-get-and- post-undefined-problem) – 2012-04-17 18:16:05