473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need to retrieve primary key

18
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):

Expand|Select|Wrap|Line Numbers
  1. // Update respondent info
  2. mysql_query("UPDATE TABLE SET Q1 ='$Q1' WHERE passcode='{$_SESSION['passcode']}'")
  3. 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?

Expand|Select|Wrap|Line Numbers
  1. function get_current_insert_id($TEST)
  2. {
  3.     $q = "SELECT LAST_INSERT_ID() FROM $TEST"; 
  4.     return mysql_num_rows(mysql_query($q)) + 1;
  5. }
I'm not sure if this should under PHP but hopefully someone can help me.
Thanks for taking the time to help me out.
Feb 11 '09 #1
1 2282
help4me
18
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_id();
Feb 12 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Eric B. | last post by:
Hi, I'm somewhat new to MySql. I've been using it for a while, but pretty much out of the box setup, and am starting to suffer heavily with my larger tables. I have a table with 5,000,000+...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
0
by: Dimitris Katsikas | last post by:
Hi everybody, I am trying to find a way to export automatically an entire database schema into an .xsd A graphical way is to drag & drop the tables from Server Connection into an empty .xsd...
2
by: edself | last post by:
Greetings, I am semi-new to Access and have a query question. I presume the solution is easy, but need some help. I have created a database with a Contact table. The contact table contains...
3
by: ben.werdmuller | last post by:
Hi, Is there an easy way in ASP/VBscript to grab an autonumber (primary key) field just after an SQL insert? This is probably easy, but I'm stuck .. Cheers.
2
by: SueA | last post by:
Can anyone help me with the code to retrieve the name of the PrimaryKey field of the current table? For instance: qryMfrsAndBrands is based on the tables: tblBrands and tblMfrs...
1
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I...
3
by: olorunfunmi | last post by:
hi there, pls how can i retrieve the value of a primary key in a table using a stored procedure. i tried sp_pkeys but that just displays the column name of the primary key and not the value thanks
2
by: singhanand2009 | last post by:
how could i retrieve data from database for a particular field. example- i have got a table having id as primary key, password, and other entity. how could i retrieve only one colum such as id.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.