I’m using Dreamweaver as I’m still learning PHP.
I have an insert form and I want it to direct me to the detail page for the record just inserted. I have done this in the past but, have forgotten how I did it, I passed a url parameter with the record ID and picked it up on the detail page.
Here’s my insert code, any help would be great.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO tl_courses (course_name, course_type, course_category, price_option, price, start_date, duration, location_option, country, region, town, postcode, results, awarding, content, requirements, additional, qualification) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['course_name'], "text"),
GetSQLValueString($_POST['course_type'], "text"),
GetSQLValueString($_POST['course_category'], "text"),
GetSQLValueString($_POST['price_option'], "text"),
GetSQLValueString($_POST['price'], "text"),
GetSQLValueString($_POST['start_date'], "date"),
GetSQLValueString($_POST['duration'], "text"),
GetSQLValueString($_POST['location_option'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['region'], "text"),
GetSQLValueString($_POST['town'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['results'], "text"),
GetSQLValueString($_POST['awarding'], "text"),
GetSQLValueString($_POST['content'], "text"),
GetSQLValueString($_POST['requirements'], "text"),
GetSQLValueString($_POST['additional'], "text"),
GetSQLValueString($_POST['qualification'], "text"));
mysql_select_db($database_dbconnect, $dbconnect);
$Result1 = mysql_query($insertSQL, $dbconnect) or die(mysql_error());
$insertGoTo = "dates_adder.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Do you know the ID of the record you’ve just inserted? If not, you’ll need to write a SELECT query to get the ID then just use:
To get the ID, either use mysql_insert_id() or write a query such as: