• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

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
// 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)
			('$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());
 //---------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");

Open in new window

1 Solution
because you closed the connection on line 11. You must keep the connection opened before you call mysql_insert_id()
adrake9Author Commented:
AWESOME! I've been at it for about an hour. Thank you very much.!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now