-1

Please don't mark this as a duplicate since I have already read the following post but still can't understand this issue:

MySQL UPDATE append data into column

I want to append data when users post multiple times. I have a ecommerce site. Now, if the user wants to upload several products for sale, I can't store the information. how would I go about this? should I use UPDATE syntax plus a .= or should I use INSERT plus .= ? I have tried INSERT on my query but it doesn't append anything. and update just replaces the existing data with the new one.

please help me as I like to learn.

here is my code for query:

if(isset($_POST['submit'])) {
 $sql = $conn->query("INSERT INTO user(user_id, post_title, post_description) Values('{$user}', '{$productname}', '{$post_desc}')");     
 $sql .= $conn->query("INSERT INTO user(user_id, post_title, post_description) Values('{$user}', '{$productname}', '{$post_desc}')");     
    // or should I use the below update query?
 $sql .= $conn->query("UPDATE user SET post_title = '{$productname}', post_description = '{$post_desc}' WHERE user_id=$user");

}

9
  • seriously did you really had to give it a -1? like if I am trying to waste the communities time? Oh my God. Commented Aug 16, 2015 at 1:35
  • Can you provide us with some code please? Commented Aug 16, 2015 at 1:39
  • @xElsa sure one sec please. Commented Aug 16, 2015 at 1:39
  • stackoverflow.com/help/how-to-ask Commented Aug 16, 2015 at 1:40
  • Whomever gave me a +1 thank you. However, I promise to learn how to ask questions here. but I am a newbie. So sorry. Commented Aug 16, 2015 at 1:46

1 Answer 1

0

just add a new row for each post:

$sql = $conn->query("INSERT INTO user(user_id, post_title, post_description) Values('$user', '$productname', '$post_desc')");
Sign up to request clarification or add additional context in comments.

12 Comments

I have already tried this but it wouldn't add a new row.
well it should so try adding echo $conn->error; after querying to see if there is an error.
i did ask for the error and I got this: Duplicate entry '4' for key 'PRIMARY' what does this mean? thanks.
that shouldn't be the problem but you can change the variable name just in case. but are you getting an error from what I just commented?
I think I know what it means. this is saying that you can't insert twice in the same field but my problem is that I need to create a new row for the same user but it wouldn't.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.