Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Retrieving Primary Key (I need help!)
Old 02-11-2009, 05:50 PM Retrieving Primary Key (I need help!)
SKP
SKP's Avatar
Novice Talker

Posts: 14
Trades: 0
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):

PHP 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?

PHP Code:
function get_current_insert_id($TABLE 

    
$q "SELECT LAST_INSERT_ID() FROM $TABLE ";  
    return 
mysql_num_rows(mysql_query($q)) + 1

Thanks for taking the time to help me out.
SKP is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-12-2009, 01:49 PM Re: Retrieving Primary Key (I need help!)
SKP
SKP's Avatar
Novice Talker

Posts: 14
Trades: 0
I found the answer. I just need to insert the following right after I save the 1st data, then replace passcode with ID.


PHP Code:
$_SESSION['ID']=mysql_insert_id(); 

SKP is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Retrieving Primary Key (I need help!)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11277 seconds with 12 queries