Jump to content

[SOLVED] Urgent pls help!


pradeep79

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.