HOME       >>       Programming

Can't Make This Query Working.


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)

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


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:

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,


Thanks ^.^lol I forgot that "/" was in the variable :PAnyways.. it is working now =) Thank you //Feelay


Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.