jeff5656 Posted August 9, 2009 Share Posted August 9, 2009 Ok, I create a new record, and the primary key automatically auto-increments: $query = "INSERT INTO icu (id_incr, rm_loc, pod, vent, vent_exp, ventever,resident, patient, mrn, pulmonologist, age, race, gender, rcf_date, rcf_date2, dx, pmhx, problist, problist_date, todo, todo_date, comments, comments_date, code, allergy, signoff_status) VALUES('','$rm_loc', '$pod', '$vent', '$vent_exp','$ventever','$resident','$patient', '$mrn', '$pulmonologist','$age', '$race', '$gender', '$rcf_date', '$rcf_date2', '$dx', '$pmhx', '$problist', '$problist_date', '$todo', '$todo_date', '$comments', '$comments_date','$code', '$allergy','a')"; mysql_query($query) or die(mysql_error()); After I run these lines, what is the correct code now to get the value of the id_incr? Link to comment https://forums.phpfreaks.com/topic/169478-solved-quickly-query-a-record-ased-on-a-primary-key-that-you-dont-yet-know/ Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 You can run the query LAST_INSERT_ID() or use PHP's mysql_insert_id Link to comment https://forums.phpfreaks.com/topic/169478-solved-quickly-query-a-record-ased-on-a-primary-key-that-you-dont-yet-know/#findComment-894175 Share on other sites More sharing options...
jeff5656 Posted August 9, 2009 Author Share Posted August 9, 2009 You mean after the query I do: $pt_id = last_insert_id(); or do I have to SELECT last_insert_id(); ugh. sorry - I m not very good with query syntax yet! Link to comment https://forums.phpfreaks.com/topic/169478-solved-quickly-query-a-record-ased-on-a-primary-key-that-you-dont-yet-know/#findComment-894185 Share on other sites More sharing options...
jeff5656 Posted August 9, 2009 Author Share Posted August 9, 2009 Ok I tried this and it seems to wrk. Thanks $pt_id = mysql_insert_id(); Link to comment https://forums.phpfreaks.com/topic/169478-solved-quickly-query-a-record-ased-on-a-primary-key-that-you-dont-yet-know/#findComment-894187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.