slj90 Posted January 18, 2010 Share Posted January 18, 2010 I want to enter the date that a user signs up.. Here is the code I use to enter the users details into the user table in my database... $query = "INSERT INTO Customer (Firstname, Surname, Username, Email, Password, Address, PostCode, City, Country) VALUES ('$newFirstname', '$newSurname', '$newUsername', '$newEmail', '$newPassword', '$newAddress', '$newPostCode', '$newCity', '$newCountry')"; What would I put to insert the date aswel? The date field in my table is 'SDate'. Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/ Share on other sites More sharing options...
bullbreed Posted January 18, 2010 Share Posted January 18, 2010 You just define a variable called $date and add it to your INSERT code $query = "INSERT INTO Customer ('Firstname', 'Surname', 'Username', 'Email', 'Password', 'Address', 'PostCode', 'City', Country date) VALUES ('$newFirstname', '$newSurname', '$newUsername', '$newEmail', '$newPassword', '$newAddress', '$newPostCode', '$newCity', '$newCountry', '$date')"; Make sure you have a date column in your database called date with a value of date Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997238 Share on other sites More sharing options...
bullbreed Posted January 18, 2010 Share Posted January 18, 2010 $date = date("Y-m-d"); Put this below you other data variables Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997239 Share on other sites More sharing options...
slj90 Posted January 18, 2010 Author Share Posted January 18, 2010 Hi bullbreed, I have done what you said and it doesn't appearing to be working. The field in my table is a 'date' field Here is my code now: $date = date("YYYY-MM-DD"); $query = "INSERT INTO Customer (Firstname, Surname, Username, Email, Password, Address, PostCode, City, Country, SDate) VALUES ('$newFirstname', '$newSurname', '$newUsername', '$newEmail', '$newPassword', '$newAddress', '$newPostCode', '$newCity', '$newCountry', '$date')"; Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997244 Share on other sites More sharing options...
SWD Posted January 18, 2010 Share Posted January 18, 2010 If you're interested in inserting the current date or current date/time and you are using MySQL (although I'm sure the other database engines have equivalents) why not use the NOW() or CURRENT_DATE mysql variables. Just in case you're not sure what I mean: insert into news_item(news_id, title, create_date) values (1, 'Test News Item', NOW()) OR insert into news_item(news_id, title, create_date) values (1, 'Test News Item', CURRENT_DATE) Hope that helps..... Josh Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997251 Share on other sites More sharing options...
bullbreed Posted January 18, 2010 Share Posted January 18, 2010 \is your code inserting anything in to the database? Also your date column in your MySQL database shoul dbr set like this; Field---Type---Collation---Attributes---Null---Default---Extra--- Action date date No None Are you checking the form data and defining variables <?php $submit = $_POST['submit']; - (This is the name of your form) //Form data $description = addslashes(strip_tags($_POST['description'])); $all your other variables here $date = date("Y-m-d"); if ($submit){ //Check for existing fields if ($description, $other variables, ){ //Register the user $queryreg = mysql_query(" INSERT INTO Customer (`description`, `other variables`, `date`) VALUES ('$description', `$other variables` $date')"); ?> have a play around with it but use the quotes around your inserts and intos Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997262 Share on other sites More sharing options...
slj90 Posted January 18, 2010 Author Share Posted January 18, 2010 Thanks to both of you for help, I used the CURRENT_DATE function and its now working great! Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997269 Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Share Posted January 18, 2010 Switched!! IT was the server! Now, I switched back to my original check login code and it worked. Now finally all thats left is the index thing. I googled it and if I'm right, before the isset i need to define them? Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997275 Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Share Posted January 18, 2010 Switched!! IT was the server! Now, I switched back to my original check login code and it worked. Now finally all thats left is the index thing. I googled it and if I'm right, before the isset i need to define them? Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997276 Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Share Posted January 18, 2010 Thanks to everyone in the last topic that helped me realize it was the code, it was the host. For some reason I tried to post this in that topic but it wouldnt let me. So thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/#findComment-997284 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.