SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I came up with the following piece of code for the "submit articles" page for my site's staff:

    <p><b>Review date:</b><br>
    <input type="text" name="date" size="45" value="<? echo (date ("Y-m-d")); ?>">

    This way the current date shows up as default in the form. The whole mish mash is processed with an INSERT query upon hitting the submit button. See below:

    $sql = "INSERT INTO reviews SET ".
    "title='$title', " .
    "content='$content', " .
    "microcontent='$microcontent', " .
    "requirements='$requirements', " .
    "date='$date', " .
    "releasedate='$releasedate', " .
    "userID='$userID'";

    Seems OK to me, but when I check the front end page, the date that shows up is 0000-00-00

    The code I use to show the date is

    echo($row["date"]

    What have I done wrong?

  2. #2
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    The quotes work in pairs and when an initial double quote is used, it only applies until the next occurance of the double quote so in line 5 you have "text", then "date", then "45", then "<? echo (date (", then ")); ?>"

    so this causes the Y-m-d to not appear in quotes.

    i would try to use the single quotes in the following manner '<? echo(date("Y-m-d"));?>'

    i had a similar problem about a month ago and backed completely away from it and used this


    $Today=date("Y-m-d");

    then i just move Today around. but what you are doing is more elegant.

    hope this helps.

    ed

  3. #3
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i looked at my response from earlier and may be about a mile off. considering the quotes but look also at your line:

    echo($row["date"]

    and consider that it might need to be:

    echo($row["date"]);

    thanks ed

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2000
    Location
    xyz
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found that typo too, thanks.

    I solved the quotes problem like this:

    <input type="text" name="date" size="45" value=<? echo ("\"" . date ("Y-m-d") . "\""); ?>>


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
  •