Solved

concat on duplicate key unique constraint email1

Posted on 2013-01-12
7
776 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysql db 3 69
Redirect 301 from one address  to another 5 25
PHP Echo with auto submit 8 28
PHP: Best way to scan folders and process files 10 39
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 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