dprichard Posted June 14, 2007 Share Posted June 14, 2007 Sorry Posted this in the wrong forum before I have an insert and want to redirect them back to a different page upon successful insertion. What is the best way to redirect if the insert is successful? if(isset($_POST['add_folder'])) { $_SESSION['folder_doc_cat'] = $_POST["folder_doc_cat"]; $folder_name = mysql_real_escape_string($_POST["folder_name"]); $folder_description = mysql_real_escape_string($_POST["folder_description"]); $folder_creator = mysql_real_escape_string($_POST["folder_creator"]); $folder_status = mysql_real_escape_string($_POST["folder_status"]); $folder_order = mysql_real_escape_string($_POST["folder_order"]); $folder_doc_cat = mysql_real_escape_string($_POST["folder_doc_cat"]); mysql_query("INSERT INTO folders (folder_name, folder_description, folder_creator, folder_status, folder_order, folder_doc_cat) VALUES('$folder_name', '$folder_description', '$folder_creator', '$folder_status', '$folder_order', '$folder_doc_cat')") or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/55636-best-way-to-redirect-after-insert/ Share on other sites More sharing options...
Wuhtzu Posted June 14, 2007 Share Posted June 14, 2007 If you haven't outputted anything yet and still have the option to modify headers you should do this: header("Location: some/page.php"); http://php.net/header And to check if the query was successful you can do something like this: <?PHP $insert_data = mysql_query("INSERT INTO folders (folder_name,folder_description) VALUES('$folder_name','$folder_description')"); if($insert_data) { echo "Data inserted successfully"; } else { echo "Data _not_ inserted..."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55636-best-way-to-redirect-after-insert/#findComment-274906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.