Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/188877-entering-date-into-mysql-table/
Share on other sites

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

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.

 

 

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

\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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.