PHP未定义变量错误
我知道这个问题之前已经发布过,但我猜 php 新版本中有一些变化。 我正在尝试找到限制用户以留言簿形式放置多余文本的表单代码,
我的代码是:
<?php
if (mysql_connect('localhost','root','')&&mysql_select_db('phpsearch') )
{
$time = time();
$errors = array();
if (isset
($_POST['guestbook_name'],$_POST['guestbook_email'],$_POST['guestbook_message']))
{
$guestbook_name = htmlentities($_POST['guestbook_name']);
$guestbook_email = htmlentities($_POST['guestbook_email']);
$guestbook_meassage = htmlentities($_POST['guestbook_message']);
if (empty ($guestbook_name) || empty($guestbook_email) || empty ($guestbook_message))
{
$errors[] = "All information required";
}
if (strlen($guestbook_name)>25 || strlen($guestbook_email)>255 || strlen($guestbook_message)>400)
{
$errors[] = 'Exceed limit length';
}
我正在使用 aptana 文本编辑器,并将此文件命名为 .php 扩展名,但文本在 > 之后变成白色。 25 即使我忽略颜色,也会显示错误
Notice: Undefined variable: guestbook_message in
C:\xampp\htdocs\myfiles\chalo_guestbook.php on line 51
I know the question was previously posted but I guess there is some change in the php new release.
I am trying to find the code for a form limiting the users for putting excess text in the form of guestbook
my code is:
<?php
if (mysql_connect('localhost','root','')&&mysql_select_db('phpsearch') )
{
$time = time();
$errors = array();
if (isset
($_POST['guestbook_name'],$_POST['guestbook_email'],$_POST['guestbook_message']))
{
$guestbook_name = htmlentities($_POST['guestbook_name']);
$guestbook_email = htmlentities($_POST['guestbook_email']);
$guestbook_meassage = htmlentities($_POST['guestbook_message']);
if (empty ($guestbook_name) || empty($guestbook_email) || empty ($guestbook_message))
{
$errors[] = "All information required";
}
if (strlen($guestbook_name)>25 || strlen($guestbook_email)>255 || strlen($guestbook_message)>400)
{
$errors[] = 'Exceed limit length';
}
I am using aptana text editor and named this file as a .php extension but the text turns white after the >25 even if I ignore the color the error is displayed saying
Notice: Undefined variable: guestbook_message in
C:\xampp\htdocs\myfiles\chalo_guestbook.php on line 51
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面有一个拼写错误:
此外,我建议仅在显示原始数据并将其保存到数据库中时才使用
htmlentities
。这样您就可以轻松构建编辑表单并检索原始文本。You have a typo above:
Additionally I'd suggest using
htmlentities
only when displaying and saving raw data into your database. That way you can easily build an Edit-Form and retrieve the original-text.