Jump to content

[SOLVED] add random numbers in MySQL ?


plodos

Recommended Posts

<?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?

 

Link to comment
https://forums.phpfreaks.com/topic/134016-solved-add-random-numbers-in-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.