plodos Posted November 24, 2008 Share Posted November 24, 2008 <?php session_start(); include("dbconfig.php"); if (!$_SESSION['loggedIn']) { header("location:login.php"); die (); } else { $id = $_GET['id']; function generateRandomString($length = 10, $letters = '1234567890') { $s = ''; $lettersLength = strlen($letters)-1; for($i = 0 ; $i < $length ; $i++) { $s .= $letters[rand(0,$lettersLength)]; } return $s; } $a = generateRandomString(); echo $a; $sql = "INSERT INTO random (id,r) VALUES ('$id', '$a')"; //unset($a); //echo $a; $result = mysql_query($sql); if($result == 1) { echo " OK"; }else {echo "not okey";} } ?> this code is repeating the data like id random_number 1 2147483647 1 2147483647 1 2147483647 1 2147483647 1 2147483647 1 2147483647 2 2147483647 I used unset() function to forget the random number but it is not working? How can I solve the problem? Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 2147483647 is maximum value of 32bit signed integer. What type is r column in your table? Quote Link to comment Share on other sites More sharing options...
plodos Posted November 24, 2008 Author Share Posted November 24, 2008 this is my dbase table for random numbers CREATE TABLE random ( id INT NOT NULL, r INT(10), ); Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 Since 2147483647 is maximum value you can store in INT column, whatever larger value is cut down to this. Use BIGINT to store larger numbers. http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html Quote Link to comment Share on other sites More sharing options...
plodos Posted November 24, 2008 Author Share Posted November 24, 2008 thanks for BIGINT, thats solve the problem Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 24, 2008 Share Posted November 24, 2008 Btw: You can use mysql's RAND() function. INSERT INTO random (`id`,`r`) VALUES ('$id',FLOOR(10000000000*RAND())) Quote Link to comment 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.