Jump to content

Creating A Random String Of 16 Characters And Set As A Global Variable.


BrettHartel

Recommended Posts

Thank you for taking the time to help me.

 

I am trying to generate a string of sixteen characters that can look like 0000000000000000 to 9999999999999999 and set it as the global variable of $User_ID

 

Here is the part of the code I am having trouble with:

function genRandomString() {
 global $User_ID;
 $length = 16;
 $characters = "0123456789";
for ($p = 0; $p < $length; $p++) {
	 $User_ID .= $characters[mt_rand(0, strlen($characters))];
 } }

 

Here is my whole code:

<?php
$con = mysql_connect("localhost","******","******");
if (!$con){ die('Could not connect: . mysql_error()'); }
mysql_select_db("******", $con);
echo "Connected to: " . $con;
$eMail="$_POST[eMail]";$User_ID=""; echo "<br>My eMail: " . $eMail;
$eMailResult = mysql_query("SELECT * FROM eMail
WHERE eMail='$eMail'");
if (mysql_num_rows($eMailResult) == 0){
echo "<br>eMail is Unique"; }
else { echo "eMail is NOT Unique<br>";}
function genRandomString() {
 global $User_ID;
 $length = 16;
 $characters = "0123456789";
for ($p = 0; $p < $length; $p++) {
	 $User_ID .= $characters[mt_rand(0, strlen($characters))];
 } }
echo "<br>User ID: " . $User_ID;
mysql_close($con);
?>

Edited by BrettHartel
Link to comment
Share on other sites

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.