Jump to content

Archived

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

redarrow

using the insert with now()

Recommended Posts

Sorry but this is from a post on here, i checked the staement now() out on google to see if the format on the insert is correct but came up with nothink from google is the insert allowed the now() in it and if so what it does.

I understand it in a select but not in a insert please advise me cheers.


Example of the insert i saw in the code cheers.

$sql = mysql_query("INSERT INTO users (first_name, last_name, email, username, password, encryptpass, bio, signup_date) VALUES('$first_name','$last_name','$email','$username','$db_password','$info2', now(),'$random_password')") or die (mysql_error());

this is how i would do it am i correct and is the above another way or wrong cheers.

$signup_date($_POST(['signup_date']));
$signup_date=date("d:m:y");

$sql = mysql_query("INSERT INTO users (first_name, last_name, email, username, password, encryptpass, bio, signup_date) VALUES('$first_name','$last_name','$email','$username','$db_password','$info2','$signup_date','$random_password')") or die (mysql_error());

Share this post


Link to post
Share on other sites
the NOW() function inserts the current date and time into a field. Good for date, time and timestamp columns.

Share this post


Link to post
Share on other sites
first off, i'm assuming that [b]now()[/b] is meant for your signup_date?  well you have listed in your first (..) signup_date as your last column, but in your values, $random_password is your last variable. The order of the values must match the order of the columns. 

Share this post


Link to post
Share on other sites
so if the database under signup_date() got a timestamp set it will work then.

Share this post


Link to post
Share on other sites
does this look better cheers thanks.

$signup_date($_POST(['signup_date']));
$signup_date=NOW();

$sql = mysql_query("INSERT INTO users (first_name, last_name, email, username, password, encryptpass, bio, signup_date,random_password') VALUES('$first_name','$last_name','$email','$username','$db_password','$info2','$signup_date','$random_password')") or die (mysql_error());

Share this post


Link to post
Share on other sites
now() is a sql function, not a php function.

[code=php:0]
$sql = mysql_query("INSERT INTO users (first_name, last_name, email, username, password, encryptpass, bio, signup_date,random_password') VALUES('$first_name','$last_name','$email','$username','$db_password','$info2',now(),'$random_password')") or die (mysql_error());
[/code]

make sure that the signup_date column is type [i]datetime[/i] or varchar(20) or something that can hold 0000-00-00 00:00:00 format.

also you are specifying 9 columns but only have 8 values you are inserting. you seem to have password and encryptpass as columns but only one password type variable.

Share this post


Link to post
Share on other sites
encryptpass,

i took this out and posted to the relevent post on here your grate cheers.

I now() know cheers.

Share this post


Link to post
Share on other sites

×

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.