View Full Version : PHP MySQL Cookie Unique Indentifier

07-26-2011, 10:21 PM

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:


//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;



$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.

07-26-2011, 10:29 PM
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.

07-27-2011, 08:53 PM
Where do I find this manual? Cheers!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum