SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insert/format date

    Hi, I have the following code that is supposed to insert all this data into database. All works fine but the start_date and end_date which always comes out either 0000-00-00 or 2010-08-04, or simillar but never the correct date.

    I am having trouble formating the date into correct format which is year-month-day (0000-00-00). What I am trying to insert is month-day-year (00-00-0000). Now I need to format it and insert it into database. In MySql, the fields are of 'date' type.

    I played with strtotime, date_format, date, none worked for me. I might be doing something wrong. If anyone can shed some light at this I would appreciate it.

    Code:
    <?
    include "login/login.php";
    include "login/header.php";
    include "db_connect.inc";
    $client_name=$_POST['client_name'];
    $timestamp=$_POST['timestamp'];
    $start_date= $_POST['start_date'];
    echo $start_date;
    $end_date=$_POST['end_date'];
    $gender=$_POST['gender'];
    $home_number=$_POST['home_number'];
    $mobil_number=$_POST['mobil_number'];
    $email=$_POST['email'];
    $website=$_POST['website'];
    $country=$_POST['country'];
    $state=$_POST['state'];
    $city=$_POST['city'];
    $escorts=$_POST['Escorts'];
    $visiting=$_POST['Visiting'];
    $masseuses=$_POST['Masseuses'];
    $dancers=$_POST['Dancers'];
    $fetish=$_POST['Fetish'];
    $extra_notes=$_POST['extra_notes'];
    $top_description=$_POST['top_description'];
    $bottom_description=$_POST['bottom_description'];
    ?>
    <html>
    <head>
    <title>Control Panel - Bella V.1</title>
    
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    </head>
    
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" rightmargin="0" leftmargin="0" topmargin="0">
    <center>
    <TABLE width="50%" border="0" topmargin="40">
    <TR>
       <TD height="200">
       <center>
    <?php 
    $query="INSERT INTO clients_info (client_name, timestamp, start_date, end_date, gender,home_number,mobil_number,email,website,country,state,city,escorts,visiting,masseuses,dancers,fetish,extra_notes,top_description,bottom_description) VALUES ('$_POST[client_name]','$_POST[timestamp]','$start_date','$_POST[end_date]','$_POST[gender]','$_POST[home_number]','$_POST[mobil_number]','$_POST[email]','$_POST[website]','$_POST[country]', '$_POST[state]','$_POST[city]','$_POST[Escorts]','$_POST[Visiting]','$_POST[Masseuses]','$_POST[Dancers]','$_POST[Fetish]','$_POST[extra_notes]','$_POST[top_description]','$_POST[bottom_description]')";
    if(!mysql_db_query($dbname,$query,$link_id)) die(mysql_error());
    echo "success in database entry.";
    ?>
      </center>
       </TD>
    </TR>
    </TABLE>
    </center>
    </body>
    </html>

  2. #2
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the format for the date field in the database?
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apologies for hijacking this post, but I have a similar problem and didn't want to raise a new post for it - So Apologies for everyone if this offends. I've searched the forum, and web and my two books and still can't find out how to change a date format.

    In my MySQL database I have rows with a date in (Format = yyyy-mm-dd).

    In my PHP I'm getting the date from the database along with all the other information stored but I only want to print the date in the format "mmm yyyy".

    This is my code so far.

    PHP Code:
    $checkdate1=mysql_result($result,$i,"checkdate");
    $checkdate=date('M Y', $checkdate1);
    <td align="center"><font face="Arial"><? echo $checkdate?></font></td>
    This just prints out JAN 1970 though!!!

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I've got this far with the full code, it formats the date to the correct format now, but it keeps the first date for all the rows! How can I adapt it for every row?

    PHP Code:
    <?
    $i
    =0;
    while (
    $i $num) {

    $checkdate=mysql_result($result,$i,"checkdate");
    $checkdate=date("M Y");
    $mileage=mysql_result($result,$i,"mileage");
    $defib=mysql_result($result,$i,"defib");
    $phones=mysql_result($result,$i,"phones");
    $drugcheck=mysql_result($result,$i,"drugcheck");
    $checkedpin=mysql_result($result,$i,"checkedpin");

    ?></font>

    <tr>
    <td align="center"><font face="Arial"><? echo $checkdate?></font></td>
    <td align="center"><font face="Arial"><? echo $mileage?></font></td>
    <td align="center"><font face="Arial"><? echo $defib?></font></td>
    <td align="center"><font face="Arial"><? echo $phones?></font></td>
    <td align="center"><font face="Arial"><? echo $drugcheck?></font></td>
    <td align="center"><font face="Arial"><? echo $checkedpin?></font></td>
    </tr>

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it.

    PHP Code:
    <td align="center"><font face="Arial"><? echo date("M Y",strtotime($checkdate)); ?></font></td>


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
  •