Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress Template causes 404 Error

Tags:

php

wordpress

I've created a page in Wordpress and used this form as template. But when I submit the form it shows Error 404 page not found.

I've tried various scripts in php but I didnt get fruitful results. Hoping for the best answers. Thanks :)

Here is my coding

<?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>
like image 258
Daniel Avatar asked Jul 27 '26 10:07

Daniel


1 Answers

Make sure that you don't have any reserved WordPress terms in the name attributes in the fields of the form.

WordPress uses many of these reserved terms for it's internal rewriting and as a result if you using name attributes such as "name", it breaks the WordPress rewrite rules and causes this 404 Not Found page after submitting the form.

See more here: http://www.lost-in-code.com/platforms/wordpress/wordpress-404-not-found-when-submitting-form/

like image 155
tribulant Avatar answered Jul 30 '26 00:07

tribulant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!