Jump to content

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

?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.