Im trying to make a custom form and insert into the database but when I click submit nothing happens. Please help me. I did research and changed my code but still same result. I dont know why.
Thanks.

this is the code in my template named std:

<?php
/*
Template Name: Student
*/
get_header();
?>

<?php echo "google";?>

<?php

    if($_POST['Submit']){

global $wpdb;

$name=$_POST['aname'];
$roll=$_POST['aroll'];
$dept=$_POST['adept'];


if($wpdb->insert(   
    'std',
    array(

            'name' => $name,
            'roll' => $roll,
            'dept' => $dept
        )
) == false) wp_die('Database insertion failed');
    else echo "Database insertion successful<p />";

?>
<?php
}
else //else we didnt submit the form, so display the form
{
?><form action="" method="post" id="addcourse">

<label> Student Name:<input type="text" 
name="aname" size="30" /></label>

<label> Roll:<input type="text" 
name="aroll" size="30" /></label>

<label> Department:<input type="text" 
name="adept" size="30" /></label>

<BR>

<input type="Submit" id="addcoursesubmit" value="submit" />
</form>
<?php
}

{
}
?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Read more here: WP create custom table and insert data in front end


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: