我有以下代码:
<form method="post">
<input type="submit" class="ym-button ym-small" name = "Apply" style="margin-top:1em;max-width:11em" value="Apply" />
</form>
<?php
if($_POST){
if(isset($_POST['Apply'])){
Apply();
}
}
function Apply()
{
$file_handle = fopen("project-list.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts1 = explode("finished", $line_of_text);
echo "Result:<input type='text' value='$parts[0] . $parts[1].'/>";
}
fclose($file_handle);
}
?>
为什么当我按下“应用”按钮时什么都没发生?当我按下“应用”按钮时,我希望函数的结果出现在“结果”中:textbox
。
TIA
将您的代码更改为以下内容:
<form method="post">
<input type="submit" class="ym-button ym-small" name = "Apply" style="margin-top:1em;max-width:11em" value="Apply" />
</form>
<?php
if($_POST){
if(isset($_POST['Apply'])){
Apply();
}
}
function Apply()
{
$file_handle = fopen("project-list.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode("finished", $line_of_text);
echo "Result:<input type='text' value='$parts[0] . $parts[1].'/>";
}
fclose($file_handle);
}
?>
您有以下代码:
$parts1 = explode("finished", $line_of_text);
代替:
$parts = explode("finished", $line_of_text);
然后,您正在访问下面的此行上不存在的数组:
echo "Result:<input type='text' value='$parts[0] . $parts[1].'/>";
通过更正,您可以如上所述访问数组
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句