Issue
I am trying to generate a random 10 digit number and insert this into mysql on page load, so each time the page refreshes or loads there should be a different 10 digit number being inserted into the database, however at the moment it just keeps inserting the same 10 digit number again and again.
Can someone please show me where I am going wrong? Thanks.
<?php
session_start();
$db_hostname = 'localhost';
$db_database = 'hewden1';
$db_username = 'root';
$db_password = '';
$db_server = mysql_connect($db_hostname, $db_username, $db_password)
or die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
$num0 = (rand(10,100));
$num1 = date("Ymd");
$num2 = (rand(100,1000));
$num3 = time();
$randnum = $num0 . $num1 . $num2 . $num3;
$sql="INSERT INTO supplier_session (session_number)
VALUES ('$randnum')";
$result = mysql_query($sql);
?>
This is the number I am constantly getting: 2147483647
Solution
try to getting ten digit rand no
$randnum = rand(1111111111,9999999999);
Answered By - Rakesh Sharma
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.