Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP MySQL Cookie Unique Indentifier

    Hello,

    I am creating a survey and I need subject numbers to be unique to each user -- Each user has multiple rows of data (~50) that need to be different or the data will be useless. Someone suggested primary key but that did not allow two rows to have the same subject ID.

    I have it set now that I am creating a URL cookie and then extracting the subject number from that URL cookie on the subsequent survey pages...

    It works fine -- However I am finding that if two people are concurrently on the welcome page and they both receive the same subject number.

    I need to find a way that these numbers in the URL cannot overlap -- Here is the code in the header:

    Code:
    <?php
    
    include('mlwebdb.inc.php');
    //assign subject #
    $result = mysql_query("SELECT LAST_INSERT_ID(subject) FROM exp02_demog");
    $subject = mysql_result($result,0);
    if (is_null($subject)) $subject=1; else $subject++;
    
    //assign condnum, don't think is that relevant but carry anyway
    $condnum = 0;
    
    setcookie('subject',$subject);
    setcookie('condnum',$condnum);
    
    //print_r($_COOKIE);
    
    $nextURL = "exp02_welcome_02.php";
    
    
    
    ?>
    My intuition tells me that there is a MySQL or PHP command that would allow the database to update on the fly without refreshing the whole page when the user presses the continue button. Does this exists? Would this work properly? Or should I be doing something else?

    For simplicities sake I would like the subject numbers to be in sequence from 1, 2, 3, 4, 5, 6,...,n , n+1,, ...


    Thank you for your help - I appreciate it very much and feel free to ask any clarifying questions.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    A primary key can be across more than one column. See the manual for creating an AUTO_INCREMENT column and create the primary key across URL and the auto_increment column.

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where do I find this manual? Cheers!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •