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?
user_idalready present in the table.