pradeep79 Posted April 1, 2007 Share Posted April 1, 2007 Hi I'm trying to insert a row using the following query and immediately retrieve the primary key with a select query as shown below: insert query: INSERT INTO service_user( Sexuality_ID, First_Name, Last_Name, Gender_ID, Address1, Address2, Postcode, Telephone, Mobile_Phone, Faith_ID, Ethnicity_ID, Nationality, Disability, HeardAboutService, DOB, PrContact, Creating_Staff ) VALUES ( 1, 'test', NULL , 1, 'qqq', 'jjjj', NULL , NULL , NULL , 1, 1, NULL , NULL , NULL , '2000-02-12', NULL , 1 ) select query: SELECT Service_User_ID FROM service_user WHERE First_Name = 'test' AND Last_Name = NULL AND DOB = '2000-02-12' AND Address1 = 'qqq' AND Address2 = 'jjjj' AND Postcode = NULL AND Telephone = NULL AND Mobile_Phone = NULL AND Faith_ID =1 AND Ethnicity_ID =1 AND Nationality = NULL AND Gender_ID =1 AND Sexuality_ID =1 AND Disability = NULL AND Creating_Staff =1; The record is inserted without problem, but when the select query runs it returns no result. What am I doing wrong. Is it because of the NULLs? when I dont enter nulls for the colums it all works ok. Please help Quote Link to comment Share on other sites More sharing options...
pradeep79 Posted April 1, 2007 Author Share Posted April 1, 2007 I rectified it myself, sorry for this stupid question, obviously NULL should be evaluated with IS NULL or IS NOT NULL statements. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted April 1, 2007 Share Posted April 1, 2007 if you want the last inserted id value of the table, which if the number is auto incremented that is what you want use this $lastid = mysql_insert_id(); echo $lastid; // prints out the last autoincremented id much neater than querying the table for the exact information you have entered Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.