Why won't my mysql_insert_id work?

Below is the final step of my form processor. I need to get the job_id (Primary Key, Auto Increment) from the last Insert and pass it into the URL in the Header: location bit.
For some reason I can't figure out why its not doing it.

I've used the mysql_insert_id() before but I'm not getting any returned value.
any help is appreciated
-a
//---------INSERT-----------//
		
// Set up the SQL query and get it ready for input
$sql = "INSERT INTO timecard_data 
			(emp_id, prop_id, unit_id, work_type, job_duration, job_notes, job_charge, job_date)
			VALUES
			('$emp_id', '$prop_id', '$unit_id', '$work_type', '$job_duration', '$job_notes', '$job_charge', '$job_date')";

// make the actual input into the database
mysql_query($sql,$conn) or die(mysql_error());
			mysql_close($conn);
 
 //---------ADD. ACTIONS-----------//
 
 // redirect the user to back to his "dashboard" using the emp_id variable
 $id = mysql_insert_id();
 $url = ("emp-timecard.php?emp_id=" . $emp_id . "&job_id=" . $id);
 header("Location: $url");
		exit();

Open in new window

LVL 2
adrake9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
because you closed the connection on line 11. You must keep the connection opened before you call mysql_insert_id()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adrake9Author Commented:
AWESOME! I've been at it for about an hour. Thank you very much.!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.