Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试了未定义索引的解决方案,但失败,出现相同错误_Php_Undefined Index - Fatal编程技术网

Php 尝试了未定义索引的解决方案,但失败,出现相同错误

Php 尝试了未定义索引的解决方案,但失败,出现相同错误,php,undefined-index,Php,Undefined Index,我正在尝试排除未发送的错误。长话短说-我已将此错误处理程序添加到联系人表单中。 报告如下: 注意文件中的错误�EmailScript.php� 第72行:未定义索引:操作 错误出现在第66行,但我添加了我认为是解决方案的内容:-第65行到第70行。我还尝试过给`$\u请求和$action空数组“foo bar”值,以及其他尝试过的解决方案 这是我无法理解的,伙计们,能给点提示吗 <?php // ----------------------------------------------

我正在尝试排除未发送
的错误。长话短说-我已将此错误处理程序添加到联系人表单中。 报告如下:

注意文件中的错误�EmailScript.php� 第72行:未定义索引:操作 错误出现在第66行,但我添加了我认为是解决方案的内容:-第65行到第70行。我还尝试过给`$\u请求和$action空数组“foo bar”值,以及其他尝试过的解决方案

这是我无法理解的,伙计们,能给点提示吗

<?php

// ----------------------------------------------------------------------------------------------------
// - Display Errors
// ----------------------------------------------------------------------------------------------------
ini_set('display_errors', 'On');
ini_set('html_errors', 0);

// ----------------------------------------------------------------------------------------------------
// - Error Reporting
// ----------------------------------------------------------------------------------------------------
error_reporting(-1);

// ----------------------------------------------------------------------------------------------------
// - Shutdown Handler
// ----------------------------------------------------------------------------------------------------
function ShutdownHandler()
{
    if(@is_array($error = @error_get_last()))
    {
        return(@call_user_func_array('ErrorHandler', $error));
    };

    return(TRUE);
};

register_shutdown_function('ShutdownHandler');

// ----------------------------------------------------------------------------------------------------
// - Error Handler
// ----------------------------------------------------------------------------------------------------
function ErrorHandler($type, $message, $file, $line)
{
    $_ERRORS = Array(
        0x0001 => 'E_ERROR',
        0x0002 => 'E_WARNING',
        0x0004 => 'E_PARSE',
        0x0008 => 'E_NOTICE',
        0x0010 => 'E_CORE_ERROR',
        0x0020 => 'E_CORE_WARNING',
        0x0040 => 'E_COMPILE_ERROR',
        0x0080 => 'E_COMPILE_WARNING',
        0x0100 => 'E_USER_ERROR',
        0x0200 => 'E_USER_WARNING',
        0x0400 => 'E_USER_NOTICE',
        0x0800 => 'E_STRICT',
        0x1000 => 'E_RECOVERABLE_ERROR',
        0x2000 => 'E_DEPRECATED',
        0x4000 => 'E_USER_DEPRECATED'
    );

    if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
    {
        $name = 'E_UNKNOWN';
    };

    return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
};

$old_error_handler = set_error_handler("ErrorHandler");

// My code


if(isset($_REQUEST['action'])){
    $action = $_REQUEST['action'];
}
if(isset($action)){ 
    echo $action;
}

$action=$_REQUEST['action'];
if ($action=="")    /* display the contact form */
    {
    ?>
    <form  action="" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="action" value="submit">
    Your name:<br>
    <input name="name" type="text" value="" size="30"/><br>
    Your email:<br>
    <input name="email" type="text" value="" size="30"/><br>
    Your message:<br>
    <textarea name="message" rows="7" cols="30"></textarea><br>
    <input type="submit" value="Send email"/>
    </form>
    <?php
    } 
else                /* send the submitted data */
    {
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $message=$_REQUEST['message'];
    if (($name=="")||($email=="")||($message==""))
        {
        echo "All fields are required, please fill <a href=\"\">the form</a> again.";
        }
    else{        
        $from="From: $name<$email>\r\nReturn-path: $email";
        $subject="Message sent using your contact form";
        mail("asiyreh@hotmail.co.uk", $subject, $message, $from);


        }
    }  
?>

您的姓名:

您的电子邮件:

您的留言:


请更正62到70之间的行

// My code

$action='';
if(isset($_REQUEST['action'])){
    $action = $_REQUEST['action'];
}

if ($action=="")    /* display the contact form */
    {

因为您需要定义变量
$action

,这就解决了E报告错误。我在网站推荐给我的一个帖子中发现了一些东西

<?php

// ----------------------------------------------------------------------------------------------------
// - Display Errors
// ----------------------------------------------------------------------------------------------------
ini_set('display_errors', 'On');
ini_set('html_errors', 0);

// ----------------------------------------------------------------------------------------------------
// - Error Reporting
// ----------------------------------------------------------------------------------------------------
error_reporting(-1);

// ----------------------------------------------------------------------------------------------------
// - Shutdown Handler
// ----------------------------------------------------------------------------------------------------
function ShutdownHandler()
{
    if(@is_array($error = @error_get_last()))
    {
        return(@call_user_func_array('ErrorHandler', $error));
    };

    return(TRUE);
};

register_shutdown_function('ShutdownHandler');

// ----------------------------------------------------------------------------------------------------
// - Error Handler
// ----------------------------------------------------------------------------------------------------
function ErrorHandler($type, $message, $file, $line)
{
    $_ERRORS = Array(
        0x0001 => 'E_ERROR',
        0x0002 => 'E_WARNING',
        0x0004 => 'E_PARSE',
        0x0008 => 'E_NOTICE',
        0x0010 => 'E_CORE_ERROR',
        0x0020 => 'E_CORE_WARNING',
        0x0040 => 'E_COMPILE_ERROR',
        0x0080 => 'E_COMPILE_WARNING',
        0x0100 => 'E_USER_ERROR',
        0x0200 => 'E_USER_WARNING',
        0x0400 => 'E_USER_NOTICE',
        0x0800 => 'E_STRICT',
        0x1000 => 'E_RECOVERABLE_ERROR',
        0x2000 => 'E_DEPRECATED',
        0x4000 => 'E_USER_DEPRECATED'
    );

    if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
    {
        $name = 'E_UNKNOWN';
    };

    return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
};

$old_error_handler = set_error_handler("ErrorHandler");

// My code

$action = $_REQUEST['action'] ?? '';

if ($action=="")    /* display the contact form */
    {
    ?>
    <form  action="" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="action" value="submit">
    Your name:<br>
    <input name="name" type="text" value="" size="30"/><br>
    Your email:<br>
    <input name="email" type="text" value="" size="30"/><br>
    Your message:<br>
    <textarea name="message" rows="7" cols="30"></textarea><br>
    <input type="submit" value="Send email"/>
    </form>
    <?php
    } 
else                /* send the submitted data */
    {
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $message=$_REQUEST['message'];
    if (($name=="")||($email=="")||($message==""))
        {
        echo "All fields are required, please fill <a href=\"\">the form</a> again.";
        }
    else{        
        $from="From: $name<$email>\r\nReturn-path: $email";
        $subject="Message sent using your contact form";
        mail("asiyreh@hotmail.co.uk", $subject, $message, $from);


        }
    }  
?>

您的姓名:

您的电子邮件:

您的留言:


然而,现在我在填写表单时没有收到任何错误-它加载的是一个空白页。从我所读到的内容来看,虽然我并不假装完全理解,但这是某种类型的服务器问题。显然,安装Xamp修复了它,但我相信服务器是一个树莓pi,所以没有Xamp只灯。我明天会再次开始,伙计们,全天为助攻准备thx

在提交表单之前(即页面加载时)是否会出现错误?是的,它会在@showdev-加载页面后立即-在向表单提交任何值之前出现。您似乎试图访问一个不存在的
$\u请求
键(即“未定义索引”)。这很可能发生在您第二次定义
$action
$action=$\u请求['action']。您只需要定义一次,您就可以考虑使用PHP来定义它,而不管它在<代码> $i请求< /C> >(或<代码> $POST < /COD> >数组中存在:<代码> $Actudio =!空($_POST['action'])$_POST['action']:''Thx@DroidDev。毫无疑问,你们是网络上最棒的,但你们对任何重复嗅探的惩罚也是——迅速和致命的——DIt只定义了一次@showdev——最初错误在第66行——我添加了第65行到第70行。但即使我把它拿走,我也会犯同样的错误