SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,665
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    add a date and number

    I set up a table
    CREATE TABLE `Properties` (
    `id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `memberid` SMALLINT UNSIGNED,
    `title` VARCHAR(50),
    `bldg` SMALLINT UNSIGNED,
    `unit` SMALLINT,
    `sqrfeet` SMALLINT,
    `pkng` CHAR(1),
    `type` CHAR(1),
    `saleprice` INT,
    `rentprice` INT,
    `startdate` DATE,
    `enddate` DATE,
    `desc` TEXT,
    `bath` FLOAT,
    `room` FLOAT,
    `image1` VARCHAR(255),
    `image2` VARCHAR(255),
    `image3` VARCHAR(255),
    `image4` VARCHAR(255),
    `image5` VARCHAR(255),
    `image6` VARCHAR(255),
    `display` CHAR(1),
    `datecreated` DATE NOT NULL,
    PRIMARY KEY (`id`),
    FOREIGN KEY (`memberid`) REFERENCES Members(`id`)
    );

    which seems to be fine as I put it phpmyadmin, but when i try to insert a record using,
    INSERT INTO `Properties` (`memberid`,`title`,`bldg`,`unit`,`sqrfeet`,`pkng`,`type`,`saleprice`,`rentprice`,`startdate`,`enddate`,`desc`,`bath`,`room`,`image1`,`image2`,`image3`,`image4`,`image5`,`image6`,`display`,`datecreated`) VALUES (2,'',1710,305,2100,0,0,6,9,CURDATE(),CURDATE(),'',1,1,'','','','','','',0,CURDATE())
    It works... The only thing is that I try to make the saleprice, rentprice, startdate and enddate fields optional but I get an error when I try
    INSERT INTO `Properties` (`memberid`,`title`,`bldg`,`unit`,`sqrfeet`,`pkng`,`type`,`saleprice`,`rentprice`,`startdate`,`enddate`,`desc`,`bath`,`room`,`image1`,`image2`,`image3`,`image4`,`image5`,`image6`,`display`,`datecreated`) VALUES (2,'',1710,305,2100,0,0,,,,,'',1,1,'','','','','','',0,CURDATE())
    I get an error.

    What is wrong?
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by lukeurtnowski View Post
    I get an error.

    What is wrong?
    something is missing

    you can't have commas with nothing in between them like that
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Highlighting the error:

    Code:
    VALUES (2,'',1710,305,2100,0,0,,,,,'',1,1,'','','','','','',0,CURDATE())

  4. #4
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,665
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks
    "Oh, and Jenkins--apparently your mother died this morning."


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
  •