Mohammad
Mohammad

Reputation: 327

rand code via PHP not working online

PHP code:

$code=rand(1000000000,9000000000);

$sql=mysql_query("INSERT INTO `form` (`code`,date) VALUES ('$code',now())");

This code works locally but not online. All code save to database is: 2147483647. How to solve this?

Upvotes: 0

Views: 101

Answers (2)

cb0
cb0

Reputation: 8613

2147483647 = 2^31 − 1 

this is the last integer which can be represented by mysql. I think you should change the type to 'bigint' and everything will be fine.

Upvotes: 1

Tarek
Tarek

Reputation: 3798

Change the type of your field from int to bigint

Check this http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

(11.1.4.1. Integer Types (Exact Value))

Int is between -2147483648 AND 2147483647

BigInt is between -9223372036854775808 AND 9223372036854775807

Upvotes: 3

Related Questions