countrygyrl Posted May 20, 2010 Share Posted May 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202441-date-issues/ Share on other sites More sharing options...
countrygyrl Posted May 20, 2010 Author Share Posted May 20, 2010 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); } Quote Link to comment https://forums.phpfreaks.com/topic/202441-date-issues/#findComment-1061420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.