Solved

concat on duplicate key unique constraint email1

Posted on 2013-01-12
7
783 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

696 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