I have created a template for form validation and when i run it error says EPIC 404...article not found....I dont know anything about Wordpress so anyone can sort it out how to validate my custom form
<?php
if(isset($_POST['submit']))
{
$fullname=$_POST['fullname'];
$age=$_POST['age'];
$email=$_POST['email'];
if(!empty($fullname) && !empty($age) && !empty($email))
{
$dbc=mysqli_connect('localhost','root','root','wordpress');
$query="SELECT * FROM wp_mypage WHERE email='$email'";
$result=mysqli_query($dbc,$query);
$data=mysqli_fetch_array($result);
$val=mysqli_num_rows($data);
if($val==0)
{
$query="INSERT INTO wp_mypage ('$fullname','$age','$email')";
mysqli_query($dbc,$query);
header("Location : http://localhost/wordpress/?page_id=67");
}
else
{
$status='Already Subscribed';
header("Location : http://localhost/wordpress/?page_id=73");
}
}
else
{
$status='Please fill all the fields';
header("Location : http://localhost/wordpress/?page_id=73");
}
mysqli_close($dbc);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
Name
<input id="name" name="name" type="text" required>
<br>Age
<input id="name" name="age" type="number" required>
<br>Email
<input id="email" name="email" type="email" required>
<input type="submit" value="Submit" />
</form>
I dont know whether to use $_SERVER or redirect to the page-id...
$wpdb
, especially$wpdb->prepare()
. Your code is an invitation for hackers.