Skip navigation
Currently Being Moderated

How to generate a unique random number in a MySQL db

Dec 28, 2011 2:48 AM

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

 
Replies
  • Currently Being Moderated
    Dec 28, 2011 3:03 AM   in reply to tonybabb

    Why not just create a registration page and login?  Then their form could be stored in the database under their "user_id" or something and if they needed it later, they could just login and that info could be displayed to them using their user id.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 28, 2011 3:59 AM   in reply to tonybabb

    Ok here is a way to do it.

    In your head put this:

     

    <?php
     $num = rand(98564654, 415231564);                     
    ?> 
    

     

    This will pull a random number inbetween 98.5 million and 415.2 million.

     

    Or change those numbers to whatever.

     

    Then put something like this above your form:

     

    <p>Application ID: = <?php echo $num;?></p>

     

    This will show Application ID: = Random Number

     

    Then in your form, create a hidden field and for the value put this:

     

    value="<?php echo $num; ?>

     

    So your hidden field might look like this on the form:

     

    <input name="myNum" type="hidden" id="hiddenField" value="<?php echo $num; ?>"/>

     

    Then have that field go into your database for the user id or whatever you want and you can use that to pull their records in an e-mail.

    Hope that helps some.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 1, 2012 8:06 AM   in reply to tonybabb

    In your code, you have:

     

     VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, $s)",

     

    Change the $s to %s and that should fix the problem for you.

    Let me know.  Thanks!

     

    Chad

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points