PHP未定义变量错误

发布于 2024-12-28 22:54:00 字数 1122 浏览 2 评论 0原文

我知道这个问题之前已经发布过,但我猜 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2025-01-04 22:54:00

上面有一个拼写错误:

 $guestbook_meassage = htmlentities($_POST['guestbook_message']);

此外,我建议仅在显示原始数据并将其保存到数据库中时才使用 htmlentities 。这样您就可以轻松构建编辑表单并检索原始文本。

You have a typo above:

 $guestbook_meassage = htmlentities($_POST['guestbook_message']);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文