osherdo Posted May 5, 2016 Share Posted May 5, 2016 I am trying to insert multiple rows to a column in mysql like this: INSERT INTO `sportsapp`.`exercises` (`id`, `image_path`, `name`, `category`) VALUES ('3', 'exercises/biceps/barbell_curls_lying_against_an_incline.jpg', 'Barbell Curls Lying Against An Incline', 'Biceps'), ('4','exercises/biceps/cable_hammer_curls_-_rope_attachment','Cable hammer Curls - Rope Attachment','Biceps'); I am getting an error in return: #1062 - Duplicate entry '3' for key 'PRIMARY' I tried to google and understand what's the reason for it, but I dont get it. I do have already a primary key, and I don't know why it generates another primary key, Could you please try to help with this? Quote Link to comment https://forums.phpfreaks.com/topic/301163-unable-to-insert-multiple-records-to-a-row/ Share on other sites More sharing options...
Solution osherdo Posted May 5, 2016 Author Solution Share Posted May 5, 2016 ignore it, I have mistakenly tried to insert to the same id that already existed, and it thrown an error. Quote Link to comment https://forums.phpfreaks.com/topic/301163-unable-to-insert-multiple-records-to-a-row/#findComment-1532850 Share on other sites More sharing options...
cyberRobot Posted May 9, 2016 Share Posted May 9, 2016 Is the "id" column set to auto increment? If so, you could leave it out of the query. INSERT INTO `sportsapp`.`exercises` (`image_path`, `name`, `category`) VALUES ('exercises/biceps/barbell_curls_lying_against_an_incline.jpg', 'Barbell Curls Lying Against An Incline', 'Biceps'), ('exercises/biceps/cable_hammer_curls_-_rope_attachment', 'Cable hammer Curls - Rope Attachment', 'Biceps'); Quote Link to comment https://forums.phpfreaks.com/topic/301163-unable-to-insert-multiple-records-to-a-row/#findComment-1532952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.