WordPress running SQL query to update database from form

Basically I want to take information in from a form and use a separate php page to update the database.

so here is the original wordpress php page (add_person.php):

Read More
<?php
/*
Template Name: tpl_add_person
*/
?>

<?php get_header(); ?>
<div id="container">
    <h2><?php echo the_title(); ?></h2>

    <?php
        if (is_user_logged_in()): ?>
            <form action="/wordpress/add_user.php" method="post">
                <input name="forename" type="text">
                <input type="submit" value="submit">
            </form>

        <?php endif; ?>

</div>
<?php get_footer(); ?>

And here is the add_user.php form to update the database (note this works if I put it on the above page with dummy information and let it update the database on page load)

<?php
    global $wpdb;

    $wpdb->insert('tbl_pupils',
        array(
            'forename'=>$_POST['forename']
        ),
        array(
        '%s'           
        )
    );
?>

But my problem is that when i click the submit button it shows the homepage, nothing done to the database and the url link in the url address bar is: localhost/wordpress/add_user.php

can anyone help?

Related posts