Jump to content
xisto Community
Feelay

Can't Make This Query Working.

Recommended Posts

Hi again.

I am trying to make a new Register script. But now, there is only one thing that is not working.. I can't make the following query work.

mysql_query("INSERT INTO members(username, password, email, register_date) VALUES ('$user','$pass','$email', '$reg_date')") or die("Failed to register.<br> Error:".mysql_error());


this is the current date variable, that is causing the error. (if I remove it from the query, it works just fine)
$reg_date=date("Y/m/d");

this is the error I am getting:

Error:Data truncated for column 'register_date' at row 1


in the database I gave it the data type int, because the date is only made out of numbers.

Thanks for your help //Feelay
Edited by Feelay (see edit history)

Share this post


Link to post
Share on other sites

Your query don't work because your variable stores a string like "2008/06/13", the "/" character cause this error to happen.

To fix it simply change your variable's date format to:

<?php$reg_date=date("Ymd");?>
But this can lead to get problems with the register_date field, i'm not sure about this.

A better solution is to change the data type of the register_date field to date and change the sql query to:

<?phpmysql_query("INSERT INTO members(username, password, email, register_date) VALUES ('$user','$pass','$email', NOW())") or die("Failed to register.<br> Error:".mysql_error());?>
Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.