WordPress.org

Ready to get started?Download WordPress

Forums

Submit data into mysql database using wordpress? (2 posts)

  1. scm22riri
    Member
    Posted 1 year ago #

    I'm having trouble figuring out a way to insert data into my own mysql database setup within wordpress. What am I doing wrong?

    http://carlots.net/blog/cars-3/

    <?php
    
    global $wpdb;
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    
    $table_name = $wpdb->prefix . 'customers';
    $wpdb->insert( $table_name,
    array( 'name' => $name,
    'email' => $email,
    'phone' => $phone,
    'address' => $address),
    array('%s','%s','%s','%d',));
    ?>
    
    <form type="post" action="cars-3/" >
    
    <label for="name">Name:</label>
    <input name="name" type="text" />
    <br/>
    <label for="email">Email:</label>
    <input name="email" type="text" />
    <br/>
    <label for="phone">Phone:</label>
    <input name="phone" type="text" />
    <br/>
    <label for="address">Address:</label>
    <input name="address" type="text" />
    <br/>
    <input type="submit">
    </form>
    <br/><br/>
    <div id="feedback"></div>
    <br/><br/>
  2. dc5ala
    Member
    Posted 1 year ago #

    Hard to tell without more informations. Is $address really a decimal number? Do you get any error (hint: set WP_DEBUG to true)? Do you get an id via $wpdb->insert_id? Have you tried $wpdb->print_error()? ...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.