<form action = "numbericalInput.php" method = "Get">
Please enter the number of input areas you wish
<input type = "text" name = "amountOfEntry"/>
<input type = "submit" name = "GO"/>
</form>
<?php
if(!empty($_GET("amountOFEntry")){
for($i = 0; $i < $_GET("amountOFEntry"); $i++){
<input type= "text" name = "nums[]" size = "2" />
}
}
?>我尝试做的是让用户在文本区域中输入一个值,然后让我为他们提供适量的文本输入,让他们在其中输入值。所以用户输入10,他们有10个文本输入和一个提交按钮或其他东西。我知道这条线不能在它所在的地方工作
<input type= "text" name = "nums[]" size = "2" />但我确信这是沿着正确的路线进行的?另外,这一行有什么问题?
if(!empty($_GET("amountOFEntry")){谢谢
发布于 2009-10-21 17:12:09
用法:isset() http://php.net/manual/en/function.isset.php
<form action = "numbericalInput.php" method = "Get">
Please enter the number of input areas you wish
<input type = "text" name = "amountOfEntry"/>
<input type = "submit" name = "GO"/>
</form>
<?php
if(isset($_GET['amountOfEntry'])){
for($i = 0; $i < $_GET['amountOfEntry']; ++$i){
?><input type= "text" name = "nums[]" size = "2" /><?
}
}
?>这将检查是否存在$_GET'amountOFEntry'
还请注意,请使用++$i而不是$i++。这里有一个小小的性能提升。不是很多,但它值得去做。
请注意,变量将区分大小写,您将在表单中使用amountOfEntry,并在循环中使用$_GET'amountOFEntry‘。(注大写F)
发布于 2009-10-21 17:14:55
$_GET是一个数组,你必须使用[]来获取元素。所以:
if(!empty($_GET['amountOFEntry']){发布于 2009-10-21 17:21:18
如上所述,$_GET返回值的数组。所以使用方括号来找到你想要的变量。你也不能把HTML和PHP混在一起。因此,您需要使HTML成为字符串(通过引用它),并让用户echo (或print)输出该字符串。
if(!empty($_GET["amountOFEntry"]){
for ($i = 0; $i < $_GET["amountOFEntry"]; $i++) {
echo '<input type= "text" name = "nums[]" size = "2" />';
}
}此外,正如Lizard所指出的,您应该使用isset来确定是否设置了变量。
https://stackoverflow.com/questions/1599605
复制相似问题