PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] Generate a random 10 digit number and insert into mysql?

 January 17, 2022     mysql, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing