Hello everyone.Is there any way to update the unique_id inside userprofile table with random numbers ranging from 1 to 1000000000?
Here are the codes that we are using. The problem is, it generates uniform numbers. We need to have it different or unique. Our system has almost 10000 users.
We are updating our database since we have added another feature. So, we need to insert unique_id to each user for them to get access to the new feature. The codes below works fine but its functionality will take time for us to update each user. Can anyone help us revise these codes to automatically update the unique_id column in one click on a button?
<?php
include 'database/dbconfig.php';
if(isset($_POST['updateBtn'])){
$new_id = $_POST['new_id'];
$ran_num = rand(1, 10000000000);
$user_id = $ran_num+$new_id;
$query = "UPDATE userprofile SET unique_id = ? WHERE user_id = ?";
$stmt = $connection->prepare($query);
$stmt->bind_param('si', $user_id, $new_id);
$stmt->execute();
header ('Location: update_all');
}
$sql = "SELECT * FROM userprofile WHERE unique_id = '' ";
$query_run = mysqli_query($connection,$sql);
if($row = mysqli_fetch_assoc($query_run)){
while($row = mysqli_fetch_array($query_run))
{
?>
<form action="" method="POST">
<input type="text" value="<?php echo $row['user_firstname'];?>">
<input type="text" value="<?php echo $row['unique_id']?>">
<input type="text" name="new_id" value="<?php echo $row['user_id']?>">
<button type="submit" name="updateBtn">UPDATE</button>
</form>
<?php }}
?>