SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: mySQL Problem

  1. #1
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mySQL Problem

    Hey Everyone,

    In mySQL I am making a database of pictures. I'm putting the title and the date into mySQL and I keep running into a problem.

    mysql> INSERT INTO Pictures SET
    -> Title = ""Priceless: George W Bush"",
    -> Pdate = "2001-03-01";

    The reason I'm using double quotation marks is becuase when I pull the title out into a web-page with PHP I want it to appear like:

    "Priceless: George W Bush" 2001-03-01

    Is the code not working because I have the double quotation marks?

    Now my next question, this one should be very easy

    In the date format: 0000-00-00 the first four zeros is the year, but what about the other two? Is the middle two zeros the day or the last two zeros the day? I just don't want to get the day and the month switched around

    I started learning mySQL yesterday so sorry if these are super easy questions.

    Thanks!

  2. #2
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the double quotes are causing you a problem. Escape the inside quotes (put a backslash before them) and you should be okay.

    MySQL's date syntax is year, month, date.

    Good luck!
    Travis Burnside
    travis@qwk.net

    Free monitoring for your web site - http://www.qwkmon.com

  3. #3
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

  4. #4
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm still says ERROR, any other ideas?

    I tried this: Title = "/"Priceless: George W Bush"/"

  5. #5
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also tried Title = "\"Priceless: George W Bush"\" and that doesn't work either.

    I may just forget the quotes all together... if anyone has a way so that quotes can be pulled out around the title please post it here. Thanks!

  6. #6
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Escape the inside quotes... like this:

    "\"Priceless: George W Bush\""
    Travis Burnside
    travis@qwk.net

    Free monitoring for your web site - http://www.qwkmon.com

  7. #7
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quotes aside you are using the wrong syntax for the INSERT statement.

    It is basically like this:
    Code:
    INSERT INTO
    tablename
    { ( col1, col2 ) } 
    VALUES
    ( data1,
    data2 );
    http://www.mysql.com/doc/I/N/INSERT.html
    Last edited by MattR; May 27, 2001 at 10:16.

  8. #8
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MattR,

    Actually that is pulled right out of kevin Yank's tutorial

    I doubt he'd be wrong but who knows...

  9. #9
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are two ways of using the INSERT and UPDATE statements:

    INSERT INTO table (field1, field2, field3) VALUES (val1, val2, val3)

    or...

    INSERT INTO table SET
    field1 = val1,
    field2 = val2,
    field3 = val3

    Personally I prefer the second method as it's a lot clearer

  10. #10
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the second method is nonstandard -- I'd stick to the SQL92 method (which, to the best of my knowledge, only includes the first method).


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
  •