-3

When i click the save button after filling the form it should be saved in the database as well as should be redirected to the edit page where i can edit the fields.

Ninad
  • 63
  • 1
  • 3
  • 15

1 Answers1

0

The trick is to POST the form to the current page, save your data into the database using your favorite method and then redirecting to the next page.

Take a look at the following example:

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Insert into database
    $stmt = "INSERT INTO table (something) VALUES ('".$_POST['data']."')";

    // Redirect
    header("Location: nextpage.php");
    exit;
}
?>

<form action="<?= $_SERVER['PHP_SELF']; ?>" method="POST" role="form">
    <div>
        <label for="data">Your data to insert into the database</label>
        <input type="text" name="data" id="data" placeholder="Data to insert">
    </div>
    <button type="submit">Save</button>
</form>
Peter
  • 8,776
  • 6
  • 62
  • 95