LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-05-2014, 06:21 AM   #1
ngiw2012
LQ Newbie
 
Registered: Jun 2014
Posts: 13

Rep: Reputation: Disabled
how can I replace a record in my DB (mySql) by new record?


I'm working on centos 6.5
and I have manged to do an insert query

mysql -u root --password='pw' MatchingDB

> INSERT INTO USER_MACTable (USER, MAC) VALUES ('$user','$mac');

my question is:
how to modify the insert query above to let it replace an existing record when the MAC attribute is duplicated and to insert a new record normally when the MAC attribute isn't duplicated using phpmyadmin queries?

Last edited by ngiw2012; 06-05-2014 at 06:26 AM.
 
Old 06-05-2014, 06:42 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
UPDATE not INSERT - you should be able to search for SQL tutorials online.
 
Old 06-05-2014, 07:23 AM   #3
ngiw2012
LQ Newbie
 
Registered: Jun 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
I have tried something like this but it keeps return an error (syntax error):

INSERT INTO user_MACTable (user, MAC) VALUES ('$user','$mac')
ON DUPLICATE KEY UPDATE MAC = VALUES('$mac')

the error according to my server is near '$mac')
 
Old 06-05-2014, 08:53 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by ngiw2012 View Post
I have tried something like this but it keeps return an error (syntax error):

You do not need the values() construct if you are specifically naming the column you are changing.


Try this:

Code:
INSERT INTO user_MACTable (user, MAC) VALUES ('$user','$mac') 
ON DUPLICATE KEY UPDATE MAC = '$mac'
 
  


Reply

Tags
mysql



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make resolver ask for A record before AAAA record Skaperen Linux - Networking 25 03-02-2010 06:36 PM
NS1 'A' Record in the SOA record swamprat Linux - Networking 4 06-17-2009 08:45 AM
DDNS record and a static PTR record mou5e Linux - Networking 2 01-22-2008 01:16 AM
Shell script to find/replace build new TAB record ljungers Programming 6 01-19-2007 04:47 PM
Unable to record mic-in with SoundBlaster Live! while able to record other sources max76230 Linux - Newbie 2 03-14-2005 04:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration