php - 为什么我得到 "undefined index"?

标签 php javascript html css forms

目前我正在开发联系我们表格,当我在本地主机上运行该脚本时,我的问题是什么,错误中的名称字段和电子邮件字段如下所示:

(<br /><b>Notice</b>:  Undefined index: name in <b>E:\wamp\www\rrr\btech\index.php</b> on line <b>49</b><br />)
(<br /><b>Notice</b>:  Undefined index: email in <b>E:\wamp\www\rrr\btech\index.php</b> on line <b>49</b><br />)

点击提交后返回undefined syntax error.

<tr>
<td valign="bottom"><span class="contactus-txt">
  <input name="textfield222" type="text" class="contact-field" style="width:125px;"   value="<?php echo $_GET['name'];?>" />
</span></td>
<td valign="bottom"><span class="contactus-txt">
  <input name="textfield2222" type="text" class="contact-field" style="width:125px;"  value="<?php echo $_GET['Email-Id'];?>"/>
</span></td>
</tr>

我使用了那个 html 代码。

谁能告诉我我犯了什么错误?

最佳答案

这是正确的方式:

<?php
$FORM['name'] = "";
$FORM['Email-Id'] = "";
if (isset($_GET['name'])) $FORM['name'] = htmlspecialchars($_GET['name']);
if (isset($_GET['Email-Id'])) $FORM['Email-Id'] = htmlspecialchars($_GET['Email-Id']);
?>
<tr>
<td valign="bottom"><span class="contactus-txt">
  <input name="textfield222" type="text" class="contact-field" style="width:125px;"   value="<?php echo $FORM['name'];?>" />
</span></td>
<td valign="bottom"><span class="contactus-txt">
  <input name="textfield2222" type="text" class="contact-field" style="width:125px;"  value="<?php echo $FORM['Email-Id'];?>"/>
</span></td>

所有变量在使用前都应该初始化。

关于php - 为什么我得到 "undefined index"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4625466/

相关文章:

php - 如何使用 $_GET ['id' 为用户创建个人资料 URL]

javascript - 一个 Angular CSS 绘图

Javascript:当 promise 完成时,然后调用相同的函数

javascript - CSS 或 JavaScript 中的只读 div

javascript - 试图将 SVG 绘制到 Canvas 上,但它被缩短了

php - 如何按日期对数组进行分类或分组

java - 如何使用 SSH 访问停止 CRON 设置

php - 如何避免 Laravel 登录重定向到最新的 AJAX 调用?

javascript - 是否可以在 Express.js 中运行 TestCafe 测试?

javascript - 使用委托(delegate)单击按钮下载文件 JQuery