Daniel Daniel - 7 months ago 14
PHP Question

Wordpress.....Why 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>


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

Answer

html5 doesn't like the empty action attribute, it does cause issues in some browsers. you have not selected a standard so i assume the browser will default to html5

<form action="#" method="POST"> 

Setting the action as # should work but one thing to watch out for is actions added before your page template is loaded, this can obviously grab the $_POST and redirects would be common so that may also be a reason.

also

Name: <input type="text" name="name" placeholder="Fill Name" required>

WP does not like when you call a field "name" it conflicts with something (i have forgotten the reason by now)

 Name: <input type="text" name="aname" placeholder="Fill Name" required>