Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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/1/wordpress/12.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 Wordpress模板导致404错误_Php_Wordpress - Fatal编程技术网

Php Wordpress模板导致404错误

Php Wordpress模板导致404错误,php,wordpress,Php,Wordpress,我在Wordpress中创建了一个页面,并将此表单用作模板。但是当我提交表单时,它显示错误404未找到页面 我用php尝试了各种脚本,但没有取得丰硕的成果。希望得到最好的答案。谢谢:) 这是我的代码 <?php /* template name: visit */ $servername= "localhost"; $username="root"; $password=""; $database="wp_chandan"; if(isset($_POST['name']) &am

我在Wordpress中创建了一个页面,并将此表单用作模板。但是当我提交表单时,它显示
错误404未找到页面

我用php尝试了各种脚本,但没有取得丰硕的成果。希望得到最好的答案。谢谢:)

这是我的代码

<?php
/*
template name: visit
*/

$servername= "localhost";
$username="root";
$password="";
$database="wp_chandan"; 


if(isset($_POST['name']) && isset($_POST['email']))
{

    $name=$_POST['name'];
    $email=$_POST['email'];
    var_dump($email);


    @mysql_connect($servername,$username,$password);
    @mysql_select_db($database);

    $query=mysql_query("insert into visitor_d (NAME,Email) values ('$name','$email') ");    
} ?>

<html>
    <head>  
        <?php get_header(); ?>
        <style type='text/css'>
        /* form elements */
        form {
            margin:100px; 
            padding: 10px 2px;
            background: #F5F5F5;  
            width: 50%;
            height:auto;
            border:1px solid green;
        }

        input {
            padding:2px;
            border:1px solid #eee;
            font: normal 1em Verdana, sans-serif;
            color:#777;
            align:center;
        }

        input.button { 
            font: bold 12px Arial, Sans-serif; 
            height: 24px;
            margin: 0;
            align:center;
            padding: 2px 3px; 
            color: #333;
            background: #e7e6e6 url(MarketPlace-images/button.jpg) repeat-x;
            border: 1px solid #dadada;
        }

        </style>
    </head>

    <form action="" method="POST">
        <fieldset>
            <legend><b><u>Visitor Details:</u></b></legend>
            Name: <input type="text" name="name" placeholder="Fill Name" required><br><br>
            Email: <input type="text" name="email" required placeholder="Enter Email"><br><br>
            <input type="submit" name="submit"><br>
        </fieldset>
    </form>
    <?php get_footer();?>
</html>


html5不喜欢空操作属性,它确实会在某些浏览器中引起问题。您尚未选择标准,因此我假设浏览器将默认为html5

<form action="#" method="POST"> 
WP不喜欢当您调用一个字段“name”时,它与某些内容冲突(我现在已经忘记了原因)

名称:

确保表单字段中的
名称
属性中没有任何保留的WordPress术语

WordPress在内部重写时使用了许多保留条款,因此,如果您使用
name
属性,如“name”,则会违反WordPress重写规则,并在提交表单后导致404找不到页面


请参阅此处的详细信息:

应位于header.php中。我也看不到模板注释
/*模板名称:我的名称*/
,因此不确定您是如何在后端选择此模板的。似乎没有将
POST
方法发送到此
url
。注释/*模板名称:我的名称*/我使用过它,但未显示在此处。您应该清理代码并按原样发布它is.Sweet,您的代码完全可以接受MySQL注入。当使用始终返回404头的自定义模板将表单发布到虚拟页面(使用重写规则)时,我觉得自己快疯了。只需将“name”更改为“_name”即可解决此问题。非常感谢你!
Name: <input type="text" name="name" placeholder="Fill Name" required>
 Name: <input type="text" name="aname" placeholder="Fill Name" required>