当error_reporting(E_ALL);
打开时,我有以下通知的示例
Notice: Undefined index: name in /home/user/public_html/directory/subdirectory/test.php on line 111
Notice: Undefined index: identity in /home/user/public_html/directory/subdirectory/test.php on line 116
如果我想在用户提交表单后使用CCD_ 2将用户输入的数据保存在文本字段中。
我当前代码的示例如下:
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['identity'], "text")
<?php $_SESSION['form'] = $_POST; ?>
<form action="<?php echo $editFormAction; ?>" method="post" name="userform" id="userform">
<input name="name" type="text" id="name" value="<?= $_SESSION['form']['name']; ?>" size="25" />
<input name="identity" type="text" id="identity" value="<?= $_SESSION['form']['identity']; ?>" size="25" />
and so on.............
知道吗?
$_SESSION['form']['name'];
和$_SESSION['form']['identity'];
是未定义的
设置他们来修复警告:
$_SESSION['form']['name'] = '';
$_SESSION['form']['identity'] = '';
附带说明:您为输入提供了相同的名称。
<input name="name">
<input name="name">
如果你的用户提交了这个,你的$_POST数组中就没有"标识"字段了。
但是,注意-s并不是真正重要的。它们会通知您可能是的问题,但如果您想避免这种通知,您必须在引用每个数组元素之前检查它-这是一项免费的大量额外工作。所以这一次你可以忘记你的通知,他们只会警告你:
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['identity'], "text")
因为第一次POST没有任何字段。这是很自然的。你应该指望空值,但空值不是问题。在很多情况下,您将访问不存在的数组元素,这很好。
注意就像你妈妈警告你外面很冷。
首先身份未定义
如果您要将identity更改为identity1(或其他内容(,则它非常有效
为了显示,您必须使用回波
<form action="<?php echo $editFormAction; ?>" method="post" name="userform" id="userform">
<input name="name" type="text" id="name" value="<?php echo $_SESSION['form']['name']; ?>" size="25" />
<input name="identity1" type="text" id="name" value="<?php echo $_SESSION['form']['identity1']; ?>" size="25" />
另一个是每件事都很好