Jump to content

Date issues


countrygyrl

Recommended Posts

I need some help with a date field in a database.  This is what I "want" to have happen, but I have tried many different things and I can't make something that should be so easy work at all!! I have a registration form and everything works great until I try and add a date joined to the database.  What I want to do is just have mySQL automatically enter the current date and time when the person registers, I don't want the date to adjust on update I just want the date and time joined to stay forever.  I had put in a column entitled joined with a type of TIMESTAMP a default of CURRENT_TIMESTAMP and NOT NULL when I add this into the database, it will not insert a new record, the form fails, when I remove it the form processes perfectly.  I want my mySQL database to handle this without any involvement from the PHP form processing, is this possible?  I am using PHP version 5.2.13 and mySQL 5.1.45 and I also want to say ahead of time that I have been googling date and looking in the manual and trying to figure out how to do this properly and I still can't figure it out so please help.

Link to comment
https://forums.phpfreaks.com/topic/202441-date-issues/
Share on other sites

OMG I can't believe it I got it to work, by adding 1 little thing to the php code. All I did was add , Now() to the INSERT statement, here was the answer in case this will help someone else out someday:

 

function addNewUser($username, $password, $email, $fname, $lname, $address, $city, $prov, $pcode, $country, $telephone, $paymentmethod, $purchasecode){
      $time = time();
  $purchasecode = $_SESSION['PurchaseCode'];

      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = GUEST_LEVEL;
      }
      $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$fname', '$lname', '$address', '$city', '$prov', '$pcode', '$country', '$telephone', '$paymentmethod', '$purchasecode', $time, Now())";
      return mysql_query($q, $this->connection);
   }

 

Link to comment
https://forums.phpfreaks.com/topic/202441-date-issues/#findComment-1061420
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.