SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    On duplicate key update,

    Hi, thanks for looking. I'm hoping someone can tell me what stupid thing I'm doing wrong. Here's the error message:

    Code:
    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 'WHERE `page` = 'alignment' LIMIT 1' at line 19
    Here's the query:
    Code:
    		         INSERT INTO `pages` (
    		                  `page`, 
    		                  `title`, 
    		                  `keywords`, 
    		                  `description`, 
    		                  `content`
    		                  )
    		         VALUES 
    		                  ('alignment', 
    		                  'Satellite dish alignment service', 
    		                  'satellite dish alignment costa blanca spain', 
    		                  'satellite dish alignment', 
    		                  '<h2>SATELLITE DISH ALIGNMENT SERVICE</h2>.....')
    		          ON DUPLICATE KEY UPDATE
    		                  `title` = 'Satellite dish alignment service',
    		                  `keywords` = 'satellite dish alignment costa blanca spain',
    		                  `description` = 'satellite dish alignment',
    		                  `content` = '<h2>SATELLITE DISH ALIGNMENT SERVICE</h2>.....'
    		          WHERE 
    		                  `page` = 'alignment'
    		          LIMIT 1
    And here's the table:
    Code:
    CREATE TABLE `pages` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `page` varchar(255) NOT NULL,
      `title` varchar(255) DEFAULT NULL,
      `content` text,
      `description` varchar(255) DEFAULT NULL,
      `keywords` varchar(255) DEFAULT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `page` (`page`),
      FULLTEXT KEY `full_index` (`page`,`title`,`content`,`description`,`keywords`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    "on duplicate key update" will update the row with the key you specified in the insert. Just eliminate the WHERE and the LIMIT


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •