How to generate a unique random number in a MySQL db

I'm creating a volunteer and also a separate vendor application form for an airshow. The volunteer and vendor info is stored in separate tables in a MySQL db, one row per volunteer or vendor. There will be about 100 volunteers and 50 vendors. When the application is submitted it should immediately be printed by the applicant, then signed and mailed in. This past year we had problems with some people who didn't immediately print their application so I'd like to still give them the option to immediately print but also send them an e-mail with a link to their specific row in the MySQL db. I have an autoincrement field as the primary key for each table, but I think sending this key to the applicant in an e-mail would be too easy for them to guess another id and access other people's info.
I'm thinking I should add a column to each table which would contain a unique random number and I would then send this key in the e-mail to the applicant. So, can anyone suggest a simple way to do this or suggest a better way of giving the applicant a way to access their own application and no-one elses after they have submitted their form?
Thanks all.
Tony Babb

Thanks so much, that was very helpful. I added the code you suggested to create and display the random number - I called it "vollink" and that worked fine. Then I added the hidden field toward the bottom of the form - it shows at line 311 when I do a "View Source in Int Explorer and then tried adding the code to add it to the table and when I tested it failed with "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1" . The test version of the page is here www.hollisterairshow.com/volunteerapp2.php . The changes I made to add it to the table is shown below , I must be missing something blindingly obvious, if you could suggest a fix I'd really appreciate it. I did add the field to the MySQL table also.
Thanks again
Tony
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO volunteers (firstname, lastname, email, thursday, friday, saturday, sunday, monday, activity, talents, specialrequests, tshirt, phone, street, city, st, zip, updatedby, vollink) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, $s)",
                       GetSQLValueString($_POST['firstname'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['thursday'], "text"),
                       GetSQLValueString($_POST['friday'], "text"),
                       GetSQLValueString($_POST['saturday'], "text"),
                       GetSQLValueString($_POST['sunday'], "text"),
                       GetSQLValueString($_POST['monday'], "text"),
                       GetSQLValueString($_POST['activity'], "text"),
                       GetSQLValueString($_POST['specialtalents'], "text"),
                       GetSQLValueString($_POST['specialrequests'], "text"),
                       GetSQLValueString($_POST['tshirt'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['street'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['st'], "text"),
                       GetSQLValueString($_POST['zip'], "text"),
        GetSQLValueString($_POST['vollink'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"));
  mysql_select_db($database_adminconnection, $adminconnection);
  $Result1 = mysql_query($insertSQL, $adminconnection) or die(mysql_error());

Similar Messages

  • 7 digit unique random number

    I would like to generate 7 digit unique random number. I have it something like this :
    Random generator = new Random();
              generator.setSeed(System.currentTimeMillis());
              //generates seven digit random number.
              return generator.nextInt(9999999) + 999999;
    But it generates 8 digit numbers sometimes. I am giving the Max limit in the braces and min limit after the "+" sign. Could anybody help me figure out what is wrong.

    This is not a horrible solution but an intelligent &
    easy solution ;)Actually this would be the easy and intellegent solution to the problem "give a random 7 digit integer."
    Random generator = new Random();
    //generates seven digit random number.
    return generator.nextInt(10000000);Though the orginal post does not specify this as part of the problem others have assumed (probably correctly) that in fact the poster wants a number between 1000000 and 9999999 (inclusive) which can easily be produced with the following modification to the above.
    Random generator = new Random();
    //generates seven digit random number.
    return generator.nextInt(9000000) + 1000000;I am confused by your response. Are you saying the becasue the original question was asking why flawed code doesn't work, that makes your solution good?

  • Generating N-digit random number??

    Hi All,
    I need to generate N-digit random number, anyone can help me?
    Thx in advance b4...

    import java.util.*;
    public class Try{
         public static void main(String []args){
              for(int i=0;i<100;i++){
                    System.out.println((int)(Math.random() * 10));
    }Yes I saw the casting, no problem with it, but I did used it alot to generate me number between a range of 1 - 9
    and if you want a range of 1 - 10, i just put a
    1+(int)(Math.random() * 10)

  • How do I create a random number generator?

    I know I've done it before...but I can't remember quite how to get it going. I'm creating a math tutor program, which generates two random numbers and asks the user to add them, and if the answer is right they get a message that gives props and if they get it wrong they're told they got it wrong.
    I can't get too far because I've forgotten how to make the number generator, so what exactly do you put in to get it?
    import java.util.*;
    public class AssignmentFour3 {
         private static Random integer = new Random();
         double number1 = 0;
         Random string1 = new Random();
         }

    DrClap wrote:
    Generally I don't write my own random number generator. I just use the java.util.Random class.I read it as though that that is what he was going to use, but wasn't able to read the API docs to figure out what methods to use. ;-)

  • How to generate a unique 8 byte number for a String in DES

    Hi All,
    Is there any way to generate a unique 8 byte number representation of String?
    I know it can be done with DES encryption (while MD5 gives 16 bytes number). My requirement is:
    Every time a String is passed - my static method should return the same unique number - all the time.
    i.e A String "AAAAAA" will return same unique number all the time. How can I achieve this (8 byte number) by DES Encryption or any other encryption?
    Thanking all in advance.

    Thanks for your reply. Won't there be any loss of data if I consider only first 8 bytes? Will Integrity be maintained.?
    In some cases my Strings can be unusually long - having length of 400 to 500.
    I want 8 bytes as I want to map the number with MySQL bigint field.

  • How to generate Serial(Unique) Number for finished goods?

    Guru's,
    How do i generate Serial(Unique) Numbers for finished goods.Suppose,if we get an order for a finished good A of 10 qty.We want to generate unique number to identify each and every A item separately for quality purpose.Any help is much appreciated.
    thanks Guru's

    Depending on serial control of item, you will need to generate serial numbers at the time of WIP Completion transaction using Serial Entry window (i.e. if serial control is At Receipt) or at the time of job creation (i.e. if you are using serial control as predefined)
    In latter case, you will have to use MES or MSCA screens to perform serialized WIP completion.
    Thanks,
    Hrishi

  • How can I create a random number and letter in a text field...

    Hi All,
    I am using application express. I want to get a random number and letter for a text field but not sure how to do this. Say I have a licence form and I want to get the licence number automatically when user wants to create a new licence and it needs to be unique. The format I am looking for is - HQ2631 something like this.
    I am thinking I have to create a trigger but not sure how to go about this....
    advanced thanks,
    Tajuddin

    Something to play with:
    Your method can generate 26 * 26 * 10000 different licence_ids
    Generating one million ids takes 20 seconds but produces between 70000 and 80000 duplicates and is rapidly getting worse (if that is something over 7%, doubling the ids generated that grows to something under 30%)
    Just see if you can live with that.
    select sum(collisions) all_duplicates,count(*) distinct_duplicates,max(collisions) max_multiple
      from (select licence_id,count(*) - 1 collisions
              from (select DBMS_RANDOM.STRING('',2) || trunc(DBMS_RANDOM.VALUE(1000,9999)) licence_id
                      from dual
                     connect by level <= :to_generate
             group by licence_id
             having count(*) > 1
           )Regards
    Etbin

  • Ideas on generating seeds for random number generators?

    Does anyone here have any ideas or know of any good links to articles that discuss how to generate good seeds for random number generators?
    I am aware that I could always probably call SecureRandom.generateSeed as one technique.
    The major problem that I have with the above is that I have no idea how any given implementation of SecureRandom works, and whether or not it is any good. (For instance, Sun seems to hide their implementation outside of the normal JDK source tree; must be in one of their semi-proprietary sun packages...)
    I thought about the problem a little, and I -think- that the implementation below ought to be OK. The javadocs describe the requirements that I am looking for as well as the implementation. The only issue that still bugs me is that maybe the hash function that I use is not 1-1, and so may not guarantee uniqueness, so I would especially like feedback on that.
    Here's the code fragments:
         * A seed value generating function for Random should satisfy these goals:
         * <ol>
         *  <li>be unique per each call of this method</li>
         *  <li>be different each time the JVM is run</li>
         *  <li>be uniformly spread around the range of all possible long values</li>
         * </ol>
         * This method <i>attempts</i> to satisfy all of these goals:
         * <ol>
         *  <li>
         *          an internal serial id field is incremented upon each call, so each call is guaranteed a different value;
         *          this field determines the high order bits of the result
         *  </li>
         *  <li>
         *          each call uses the result of {@link System#nanoTime System.nanoTime}
         *          to determine the low order bits of the result,
         *          which should be different each time the JVM is run (assuming that the system time is different)
         *  </li>
         *  <li>a hash algorithm is applied to the above numbers before putting them into the high and low order parts of the result</li>
         * </ol>
         * <b>Warning:</b> the uniqueness goals cannot be guaranteed because the hash algorithm, while it is of high quality,
         * is not guaranteed to be a 1-1 function (i.e. 2 different input ints might get mapped to the same output int).
         public static long makeSeed() {
              long bitsHigh = ((long) HashUtil.enhance( ++serialNumber )) << 32;
              long bitsLow = HashUtil.hash( System.nanoTime() );
              return bitsHigh | bitsLow;
         }and, in a class called HashUtil:     
         * Does various bit level manipulations of h which should thoroughly scramble its bits,
         * which enhances its hash effectiveness, before returning it.
         * This method is needed if h is initially a poor quality hash.
         * A prime example: {@link Integer#hashCode Integer.hashCode} simply returns the int value,
         * which is an extremely bad hash.     
         public static final int enhance(int h) {
    // +++ the code below was taken from java.util.HashMap.hash
    // is this a published known algorithm?  is there a better one?  research...
              h += ~(h << 9);
              h ^=  (h >>> 14);
              h +=  (h << 4);
              h ^=  (h >>> 10);
              return h;
         /** Returns a high quality hash for the long arg l. */
         public static final int hash(long l) {
              return enhance(
                   (int) (l ^ (l >>> 32))     // the algorithm on this line is the same as that used in Long.hashCode
         }

    Correct me if I'm incorrect, but doesn't SecureRandom just access hardware sources entropy? Sources like /dev/random?What do you mean by hardware sources of entropy?
    What you really want is some physical source of noise, like voltage fluctuations across a diode, or Johnson noise, or certain radioactive decay processes; see, for example
         http://www.robertnz.net/true_rng.html
         http://ietfreport.isoc.org/idref/draft-eastlake-randomness2/
         this 2nd paper is terrific; see for example this section: http://ietfreport.isoc.org/idref/draft-eastlake-randomness2/#page-9
    But is /dev/random equivalent to the above? Of course, this totally depends on how it is implemented; the 2nd paper cited above gives some more discussion:
         http://ietfreport.isoc.org/idref/draft-eastlake-randomness2/#page-34
    I am not sure if using inputs like keyboard, mouse, and disk events is quite as secure as, say, using Johnson noise; if my skimming of that paper is correct, he concludes that you need as many different partially random sources as possible, and even then "A hardware based random source is still preferable" (p. 13). But he appears to say that you can still do pretty good with these these sources if you take care and do things like deskew them. For instance, the common linix implementation of /dev/random at least takes those events and does some sophisticated math and hashing to try to further scramble the bits, which is what I am trying to simulate with my hashing in my makeSeed method.
    I don't think Java can actually do any better than the time without using JNI. But I always like to be enlightened; is there a way for the JVM to generate some quality entropy?Well, the JVM probably cannot beat some "true" hardware device like diode noise, but maybe it can be as good as /dev/random: if /dev/random is relying on partially random events like keyboard, mouse, and disk events, maybe there are similar events inside the JVM that it could tap into.
    Obviously, if you have a gui, you can with java tap into the same mouse and keyboard events as /dev/random does.
    Garbage collection events would probably NOT be the best candidate, since they should be somewhat deterministic. (However, note that that paper cited above gives you techniques for taking even very low entropy sources and getting good randomness out of them; you just have to be very careful and know what you are doing.)
    Maybe one source of partial randomness is the thread scheduler. Imagine that have one or more threads sleep, and when they wake up put that precise time of wakeup as an input into an entropy pool similar to the /dev/random pool. Each thread would then be put back to sleep after waking up, where its sleep time would also be a random number drawn from the pool. Here, you are hoping that the precise time of thread wakeup is equivalent in its randomness to keyboard, mouse, and disk events.
    I wish that I had time to pursue this...

  • How to generate a unique WSDL for two webservices ?

    Hi ,
    Does anyone know if there is a way to generate a unique WSDL file for two webservices ?
    Actually, the problem is more general. I have two EJB that are exposed through web services. They both contain a simple data structure that is passed back and forth.
    The Client is a C# GUI and it is having problems with that data structure. Even if it is the same data structure with the same namespace, it seems it as two different objects and so creates two different stubs ...
    I am trying to work around that from the server side, bc it does not seem that we can do it from the C# application.
    First, I am trying to generate just one WSDL that would include both webservices but I can't seem to find an easy way of doing that.
    Second, I have heard that the complex types could be referenced externaly and I think that it would do the trick as well. I don't know how to do that either.
    I am using ServiceGen Ant tags to generate my web services from an EJB.
    Did anyone encounter that issue ?
    Can any one help ?
    Thanks a lot
    Farez

    hi,
    go to t-code SNRO and create a number range from 0 to 99999999.
    call the below fm in the report by passing the created number range name to fm to generate the new number every time..
    see
    NUMBER_GET_NEXT Get next free number in a range
    CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
    NR_RANGE_NR = '01'
    OBJECT = 'YPOLLID'        "number range name created in SNRO.
    IMPORTING
    NUMBER = LS_NUMBER.       "new number with one increment..
    or
    you can try..
    you can use following code.
    select max( num ) from z_table into v_max_num.
    v_max_num = v_max_num+1.
    Regards,
    prabhudas

  • How to generate a Unique key based on a some String value

    Hello every one,
    I am sorry , If I post this question in wrong group... I have a requirement to generate a unique key ( what every it may be alpha, numeric or alpha numeric) based on some String..
    For ex : String str = "AbCX" - Gives a unique key based on "AbCX" value..
    Is there any way we can get the unique value using Java ?
    Thanks

    May be not what you are looking for, but here's may idea:
    use a sequence (db sequence) and add it the the string value. This way the value is unique, because the sequence is unique. So you could omit the string theoretically, but your requirement is met.
    It's very easy to get a unique sequence number from the db using java, depending of the technology you use (which you did not say :-( )
    Timo

  • How to fill array with random number?

    I need to fill a 3-dimensional array that has user-controlled dimension sizes with random numbers (1-10). I'm unsure of how to do this. I feel like I have to use the initialize array and maybe the build array functions somehow but I'm not entirely sure. Any help would be appreciated. Thanks.

    Something like this
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet
    Attachments:
    Array with random number.vi ‏9 KB

  • How can I alter the random number seeding in Labview?

    Is there a way to force a particular seed or dynamically reseed the random number generator in Labview?

    You could use a flat noise generator with one sample.
    It is able to be seeded.
    Tim
    agolovit wrote:
    > Is there a way to force a particular seed or dynamically reseed the
    > random number generator in Labview?

  • How to generate an incrementing batch-number per set number of rows

    Hi,
    How could you generate an incrementing batch-number per set number of rows for a table in SQL?
    The returned result set of the SQL query should show a preceding batch number per row set and incremented by 1 for the next row set.
    Eg, you want to start the batch_number by 1 for the first three returned rows of the table and than increment by 1 for the next three rows.
    The result set would look like:
    BATCH_NO, TAB_COL1, TAB_COL2, TAB_COL3, TAB_COL4, ..
    1, ...
    1, ...
    1, ...
    2, ...
    2, ...
    2, ...
    3, ...
    3, ...
    3, ...
    etc.
    Cheers.

    Many thanks guys, I would have never thought about these options.. Yes the reason for adding the preceding batch number has to do with migrating data from a source table where we only can grab small sets of rows at the time to bring across to a target table.
    Cheers.

  • How to enter a 24 digit number into a mysql db

    hi,
    i want enter a 24 digit number into a mysql db as a mathematically manipulatable value.
    when i configure the field as a bigint(24) it takes it as bigint(20)
    when i keep it as bigint and parsing a double value from my application
    it gives data truncation exception for the particular field.
    the whole process worked well when i change the field type to varchar(24),
    what i want is to enter 24 digit number into db as a mathematically manipulatable value.
    if anyone can assist me, pls reply,
    thanks,
    dushi

    you should ask in a mysql-forum. or at least in JDBC-forum here at sun-forums
    you could save it as varchar and parse it when selecting it into bigint in java and make your calculations...

  • How can I generate multiple unique random numbers?

    Hello,
    I am trying to generate multiple random numbers between a given set of numbers (1-52) and not have the same number generated twice within that set. I can compare the last and next numbers with the compare function but how would I go about comparing all of the generated numbers without using a huge list of shift registers...
    Any help/ideas are welcome and appreciated.
    Jason
    Solved!
    Go to Solution.

    Here is an implementation of Jason's solution.
    steve
    Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
    question. Give "Kudos" to replies that help.
    Attachments:
    random.vi ‏10 KB

Maybe you are looking for

  • IPAD4 w/skype no video possible fix

    If you have skype on your IPhone or IPad make sure the person you are calling has accepted your skype address I had this problem but, when I was accepted the address the IPAD worked fine That is I could hear and see the other party Hope this will hel

  • SQL query - Need your help

    Guys, I am struggling with this sql. Any better ways of writing this one ? SELECT entity_id, SUM (volume) FROM (SELECT ev.entity_id, NVL (SUM (ev.volume), 0) AS volume FROM entity_volume ev WHERE ev.entity_id IN (112764, 112800, 112878, 112916, 11297

  • How to audit database access by IP address?

    Hello, In SQL 2008 R2 Enterprise is there a built-in mechanism to be able to audit and log the SQL loginname along with their IP addresses when they access a particular database? Most of the logins only have the role for db_datareader so I need to au

  • Ipad and ipad mini vibrate through browser?

    We are looking to develop a function, hopefully through a script within a browser, to tell an ipad or an ipad mini to vibrate. Is this possible? Or do we need to create an app for it? Thanks for any help in advance, Adam

  • I have many pdfs that have the identical structure, but are NOT forms. How can I collect this data?

    I have dozens of pdfs which have the identical structure, but are NOT forms. I would like to collect data across these pdfs to analyze. Is there a way to do this?