Support » Fixing WordPress » wpdb insert issue – Not inserting correct value

  • Resolved DigitalSquid


    I’ve was trying to add a simple little form on my site to do a bit of data capture. Nothing too complicated – just getting visitors first name, last name and email address and then saving it to a table in my DB.

    Here’s the line of code I’m using to do the insert.

    $wpdb->insert('signup', array(fname => $_POST['fname'], lname => $_POST['lname'], email => $_POST['email']), array( '%s', '%d'))

    When I check the results in the DB, the fname and email fields work perfectly – they get the correct values from the form. However, the lname field always ends with a value of 0.

    What baffles me is that if I output the $_POST variables before and after the insert, they are all correct. All of them show the values that were submitted from the form.

    I’ve checked the structure of the DB fields as well, all 3 are Varchar(50), latin1_general_ci and I don’t think lname is a reserved word or anything.

    Any ideas why the $_POST[‘lname’] variable always seems to end up being inserted as 0?

  • The topic ‘wpdb insert issue – Not inserting correct value’ is closed to new replies.