0

I have a table named wp_q33uds_campaign in my MySQL database, which is defined using a plugin as follows:

$sql = "CREATE TABLE `$tablename`(
            `user_id` INT(20) NOT NULL AUTO_INCREMENT,
            `tweet1` VARCHAR(200) NOT NULL,
            `date1` VARCHAR(200) NOT NULL,
            `tweet2` VARCHAR(200) NOT NULL,
            `date2` VARCHAR(200) NOT NULL,
            `tweet3` VARCHAR(200) NOT NULL,
            `date3` VARCHAR(200) NOT NULL,
            `tweet4` VARCHAR(200) NOT NULL,
            `date4` VARCHAR(200) NOT NULL,
            `tweet5` VARCHAR(200) NOT NULL,
            `date5` VARCHAR(200) NOT NULL,
            `flag` INT(10) NOT NULL,
            `created` DATETIME,
            );";

Now, I want the same user to be able to insert multiple entries into the table ie multiple entries of the same user_id should be allowed to be inserted into the table.

The code for inserting values into the table:

if($_POST['submitted'])
{
     $table_name = $wpdb->prefix."campaign";

        $new_data = array(
                'user_id' => 4344,
                'tweet1' => $_POST['tweet1'],
                'date1' => strtotime($_POST['date1']) - 19800,
                'tweet2' => $_POST['tweet2'],
                'date2' => strtotime($_POST['date2']) - 19800,
                'tweet3' => $_POST['tweet3'],
                'date3' => strtotime($_POST['date3']) - 19800,
                'tweet4' => $_POST['tweet4'],
                'date4' => strtotime($_POST['date4']) - 19800,
                'tweet5' => $_POST['tweet5'],
                'date5' => strtotime($_POST['date5']) - 19800,
                'flag' => 1,
                'created' => current_time('mysql'),
            );
        //print_r($new_data);

        $wpdb->insert($table_name, $new_data);
}

However, the wp_q33uds_campaign table doesn't accept entries with an user_id already present in the table. THe table does accept entries with user_id not present in the table.

How can I allow my table to accept entries with a duplicate user_id?

6
  • Don't set it to auto increment Commented Sep 3, 2015 at 13:58
  • Examples like the following: stackoverflow.com/a/32366677/1816093 I am sorry it is not immediately tailored on your behalf, but it is possible Commented Sep 3, 2015 at 14:01
  • @Flyer That doesn't seem to help solve my problem. Commented Sep 3, 2015 at 14:02
  • but what @Flyer said makes sense to me in the face of it all. An auto_inc requires it to be PK . Nope, requires it to be a key. I am wrong again. Commented Sep 3, 2015 at 14:09
  • @Drew I have auto increment disabled, and there are no primary keys in the table. And yet, I can't seem to insert entries with user_id already present in the table. Commented Sep 3, 2015 at 14:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.