2
所以,我有以下幾點:爲什麼我在PHP中收到「Undefined variable」通知?
<?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]) . '" />';
}
?>
爲什麼會收到通知如下:?
Notice: Undefined variable: defaults
Arrrrrg ...你是對的。變量範圍。 我怎麼沒看到它。 – 2009-06-26 17:58:02