gpt4 book ai didi

php - 为什么我在 PHP 中收到 "Undefined variable"通知?

转载 作者:行者123 更新时间:2023-12-02 06:45:35 24 4
gpt4 key购买 nike

所以我有以下内容:

<?php
show_form();
?>


<form id="add" method="post" action="addIssue.php">
Name:
<?php input_text('name','str_name', $defaults , '1'); ?>
<input class="submit" type="submit" value="Begin download" />
<input type="hidden" name="_submitCheck" value="1"/>
</form>


<?php
function show_form($errors = '')
{
// If form is submitted, get the defaults from submitted parameters
if(empty($_POST['_submitCheck']) OR !$_POST['_submitCheck'] ){
// set our own defaults
$defaults = array('str_name' => '');

} else {
$defaults = $_POST;
}
}

// Echo text box
function input_text($elem_id, $element_name, $values, $tab='') {
echo '<input id="'.$elem_id.'" name="'.$element_name.'"';
echo ' tabindex="'.$tab.'" class="text" value="';
echo htmlentities($values[$element_name]) . '" />';
}
?>

为什么我会收到以下通知?

注意: undefined variable :默认值

最佳答案

$defaultsshow_form 函数范围内的局部变量。您需要从函数中返回它并将第一行代码更改为:

$defaults = show_form();

关于php - 为什么我在 PHP 中收到 "Undefined variable"通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1050359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com