SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2009
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mysql Primary Key not working properly

    Hi,

    i have table called image_detail which corresponds to details of image files on my server. The primary key i'm using to uniquely identify each .jpg image file is an id and the image file name. However, whenever i enter a new record and have a filename that is the same name as another file, mysql still seems to insert this record, can somone tell me why?

    UPDATED TABLE as it was giving erros before
    Code:
     CREATE TABLE image_detail (
    Id INT NOT NULL AUTO_INCREMENT,
    Filename VARCHAR(255) NOT NULL,
    Type VARCHAR(255) NOT NULL,
    Size TEXT NOT NULL,
    Location VARCHAR(255)NOT NULL, 
    Description TEXT NOT NULL,
    PRIMARY KEY(Id, Filename)
    ) DEFAULT CHARACTER SET utf8;
    test data:
    INSERT INTO image_detail (Id, Filename, Type, Size, Location, Description) VALUES
    (1, 'IMG_0075.JPG', '.jpg', '61.9kb','C:\wamp\www\Shanghai_2010\Cheng_Huang_Temple\IMG_0075.JPG', 'Temple area market'),
    (2, 'IMG_0075.JPG', '.jpg', '61.9kb','C:\wamp\www\Shanghai_2010\Cheng_Huang_Temple\IMG_0075.JPG', 'Temple area market');
    P.S I am using WAMPSERVER
    thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,832
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The primary key is the first two fields and those are different between those two records.

    What is the Id field there for? Unless you have a reason for needing multiple copies of the same filename then getting rid of that field will be the easiest way to get what you want.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2009
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need the id there because i will need to link this with different cateogries as each image file belongs to a different category.

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2009
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've found a solutin now


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
  •