redarrow Posted July 2, 2006 Share Posted July 2, 2006 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()); Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/ Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 the NOW() function inserts the current date and time into a field. Good for date, time and timestamp columns. Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/#findComment-51883 Share on other sites More sharing options...
.josh Posted July 2, 2006 Share Posted July 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/#findComment-51884 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Author Share Posted July 2, 2006 so if the database under signup_date() got a timestamp set it will work then. Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/#findComment-51885 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Author Share Posted July 2, 2006 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()); Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/#findComment-51889 Share on other sites More sharing options...
.josh Posted July 2, 2006 Share Posted July 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/#findComment-51891 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Author Share Posted July 2, 2006 encryptpass,i took this out and posted to the relevent post on here your grate cheers.I now() know cheers. Quote Link to comment https://forums.phpfreaks.com/topic/13432-using-the-insert-with-now/#findComment-51893 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.