Need to retrieve primary key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • help4me
    New Member
    • Aug 2007
    • 18

    Need to retrieve primary key

    I am doing a survey with many pages. Everyone is given the same password to get into the survey (bulk mailing) but since it is to be done anonymously, they have no unique id assigned to them. My problem is that I don't know how to save the data without it (and then select it again). I usually have the following (passcode is the unique number usually assigned to them):

    Code:
    // Update respondent info
    mysql_query("UPDATE TABLE SET Q1 ='$Q1' WHERE passcode='{$_SESSION['passcode']}'")
    or die(mysql_error());
    I need to be able to save it to a variable set to the Primary Key. I found this function and it looks like it will work to retrieve the number, but how do I save it as a variable that I can insert into the above code?

    Code:
    function get_current_insert_id($TEST)
    {
        $q = "SELECT LAST_INSERT_ID() FROM $TEST"; 
        return mysql_num_rows(mysql_query($q)) + 1;
    }
    I'm not sure if this should under PHP but hopefully someone can help me.
    Thanks for taking the time to help me out.
  • help4me
    New Member
    • Aug 2007
    • 18

    #2
    I found the answer. I just need to insert the following right after I save the 1st data then replace passcode with ID.

    $_SESSION['ID']=mysql_insert_i d();

    Comment

    Working...