Jump to content

Best way to Redirect after insert


dprichard

Recommended Posts

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());
}

Link to comment
https://forums.phpfreaks.com/topic/55636-best-way-to-redirect-after-insert/
Share on other sites

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...";
}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.