Jump to content

Recommended Posts

Hi, I have a row called code in mysql data base now what I want to do is something like this

 

$rand=rand(1111,9999);

 

$code=mysql_query("UPDATE member SET code='$rand' WHERE clan_id='1'");

 

At the moment its updating the code row with the same random number. What I want to achieve is a unique number for each member.

 

For instance

 

Currently if the $rand=1289 lets suppose

 

Every code row will become 1289  I want the code rows to be different to each other. I tried a few things up my sleeve but no luck. How can i do this? thanks any help much appreciated.

How about adding a md5 along with the random number in a larger range.

 

A simple example

<?php
$member = $_POST['member'];

if(!isset($_POST['member']) || $member == ''){
echo "Insert a member name";
} else {
$rand_number = rand(1111,50000);
$merge_code = md5("$member$rand_number");
echo $merge_code;
}
?>
<html>
<body>

<form action="" method="post">
Member: <input type="text" name="member" />
<input type="submit" name="Make Code"/>
</form>

</body>
</html> 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.