Solved

concat on duplicate key unique constraint email1

Posted on 2013-01-12
7
766 Views
Last Modified: 2013-01-13
I am using php/mysql


UC is email1

INSERT INTO renters (first_name,last_name,email1,email2,email3,phone1,phone2,phone3,information,description) VALUES ('TEST','','derrickjmiller1@gmail.com','','','','','','','
\r\n	ADD THIS PLEASE

\r\n') ON DUPLICATE KEY UPDATE renters set description=concat (description,'
\r\n	ADD THIS PLEASE

\r\n');

Open in new window


Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set description=concat (description,' \r\n ADD THIS PLEASE  \r\n')' at line 1
0
Comment
Question by:rgb192
  • 4
  • 2
7 Comments
 
LVL 25

Expert Comment

by:TempDBA
ID: 38771102
Can you be more clear with your requirements along with an example?
0
 

Author Comment

by:rgb192
ID: 38771114
insert a new row
or
add to column description
if email1 is already in the table
0
 
LVL 11

Accepted Solution

by:
mcnute earned 500 total points
ID: 38771720
Well your query isn't quite finished in the code you posted. This should do it:

ON DUPLICATE KEY UPDATE renters set description=concat (description,'somthing to add to description')";

Open in new window

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rgb192
ID: 38772148
what is difference between your code

ON DUPLICATE KEY UPDATE renters set description=concat (description,'somthing to add to description')";

and

INSERT INTO renters (first_name,last_name,email1,email2,email3,phone1,phone2,phone3,information,description) VALUES ('TEST','','derrickjmiller1@gmail.com','','','','','','','
\r\n      ADD THIS PLEASE

\r\n') ON DUPLICATE KEY UPDATE renters set description=concat (description,'
\r\n      ADD THIS PLEASE

\r\n');




maybe a
'
0
 

Author Comment

by:rgb192
ID: 38772529
delimiter $$

CREATE TABLE `renters` (
  `id` int(11) NOT NULL auto_increment,
  `first_name` varchar(100) default NULL,
  `last_name` varchar(100) default NULL,
  `email1` varchar(100) default NULL,
  `email2` varchar(100) default NULL,
  `email3` varchar(100) default NULL,
  `phone1` varchar(20) default NULL,
  `phone2` varchar(20) default NULL,
  `phone3` varchar(20) default NULL,
  `information` varchar(4000) default NULL,
  `description` varchar(9000) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `email1` (`email1`)
) ENGINE=MyISAM AUTO_INCREMENT=32 DEFAULT CHARSET=utf8$$








INSERT INTO renters (first_name,last_name,email1,email2,email3,phone1,phone2,phone3,information,description) VALUES ('test','','derrickjmiller1@gmail.com','','','','','','','') ON DUPLICATE KEY UPDATE renters set description=concat(description,'somthing to add to description')

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set description=concat(description,'somthing to add to description')' at line 1
0
 

Author Closing Comment

by:rgb192
ID: 38772536
this would work with if I have a correct uc and no primary key

so your answer is correct

I need another question about table structure
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 38772540
your syntax is wrong.
instead of adding the table name again,
ON DUPLICATE KEY UPDATE renters set description=concat (description,'
 it should be
ON DUPLICATE KEY UPDATE  description=concat (description,'
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now