WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Form Data Between Pages (2 posts)

  1. lowestofthekeys
    Member
    Posted 1 year ago #

    Hi all,

    I've been trying to setup a form that inserts data directly into the wordpress database.

    Here is my update form(insert.php):

    <?php
    /*
    Template Name: Insert
    */
    
    ?>
    <?php get_header(); ?>
    
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td><form name="form1" method="post" action="<?php bloginfo('template_url'); ?>/insert_ac.php">
    <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <tr>
    <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
    </tr>
    <tr>
    <td width="71">ID</td>
    <td width="6">:</td>
    <td width="301"><input name="id" type="text" id="id"></td>
    </tr>
    <tr>
    <td>Facility</td>
    <td>:</td>
    <td><input name="facility" type="text" id="facility"></td>
    </tr>
    <tr>
    <td>Roof Section</td>
    <td>:</td>
    <td><input name="roofsection" type="text" id="roofsection"></td>
    </tr>
    <tr>
    <td>Sq. Feet</td>
    <td>:</td>
    <td><input name="footage" type="text" id="footage"></td>
    </tr>
    <tr>
    <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    <?php get_footer(); ?>

    And it sends the data to(insert_ac.php)...

    <?php
    
    include('config.php');
    
    // Get values from form
    $id=$_POST['id'];
    $facility=$_POST['facility'];
    $roofsection=$_POST['roofsection'];
    $footage=$_POST['footage'];
    
    // Insert data into mysql
    $sql="INSERT INTO $tbl_name(id, facility, roofsection, footage)VALUES('$id', '$facility', '$roofsection','$footage')";
    $result=mysql_query($sql);
    
    // if successfully insert data into database, displays message "Successful".
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='#'>Back to main page</a>";
    }
    
    else {
    echo "ERROR";
    }
    ?> 
    
    <?php
    // close connection
    mysql_close();
    ?>

    I'm confused because each time I submit the data from the update form, it gives me an error, which leads me to believe I must have messed up the action method in the form and it's not sending the data correctly.

    Does anyone know specifically what you need to do to post data from the form on insert.php to insert_ac.php in wordpress?

  2. lowestofthekeys
    Member
    Posted 1 year ago #

    Hrrrm, I figured it out.

Topic Closed

This topic has been closed to new replies.

About this Topic