0

I am trying to add new data right after the current data. This works well,

mysql_query("UPDATE uyeler SET shoots=shoots + 1 WHERE nick='admin'")

However, its only for numbers. I tried that with normal text value

$places = "london";
mysql_query("UPDATE uyeler SET shootplaces= shootplaces + '".$places."' WHERE nick='admin'")

But all it does is that it makes the shootplaces to 0. What is the correct way to add new value to a row without deleting the current value in it ?

6
  • menace you need addition of two text? or just Concatenate of two string? Commented Jan 1, 2016 at 8:21
  • I need to add new data to shootplaces row, after the current row data (without deleting it). Commented Jan 1, 2016 at 8:22
  • What contain shootplaces ? Commented Jan 1, 2016 at 8:22
  • Is shootplaces an integer? Commented Jan 1, 2016 at 8:22
  • 1
    Use CONCAT() function Commented Jan 1, 2016 at 8:24

3 Answers 3

4

You have to use Mysql CONCAT function.

$places = "london";
mysql_query("UPDATE uyeler SET shootplaces= CONCAT(shootplaces , '".$places."') WHERE nick='admin'")
Sign up to request clarification or add additional context in comments.

Comments

1

Is your shootplaces has INT as datatype ? Anyway, you can use concat() function to add new data into new cell.

UPDATE your_table 
SET your_column = CONCAT(your_column, 'your new value') WHERE id=..

See this link for further help

1 Comment

are you adding multiple values to a single column? That violates first normal form. or are you merely adding to a string. to me it looks like you are going to store multiple locations in one column.
1

try this.

$places = "london";
     mysql_query("UPDATE uyeler SET shootplaces= concate(shootplaces , '$places') WHERE nick='admin'")

Comments

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.