Hi guys, hope you can help me. I've created a form in Dreamweaver (using the insert record wizard) which is linked to a MYSQL database. Trouble is once all the information is inputted and submitted I want the page to reload itself again so I have a fresh form to insert data again. For some reason it redirects to a new htm page (and not the PHP page I originally started with) e.g data.htm and not data.php. Any ideas would be appreciated.

Dani AI

Generated

— quick diagnosis and practical fixes based on the replies from , and .

Dreamweaver’s Insert Record server behavior often writes a “success” redirect into the generated code (it may also add a hidden field with the URL). Search the generated files for the literal filename shown after submit (for example data.htm) or for Dreamweaver’s redirect variable (commonly MM_redirectTo). Edit that server behavior or remove/change the redirect so the form does not send users to the .htm file.

A more robust pattern is Post/Redirect/Get (PRG): process the POST, then redirect back to the form page so a fresh form appears and browser refresh won’t resubmit the data. Example:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // validate and insert into DB here

    header('Location: /path/to/form.php'); // redirect to fresh form
    exit;
}

To show a one-time success message after the redirect, use a session “flash”:

session_start();
$_SESSION['flash'] = 'Record saved.';
header('Location: /path/to/form.php');
exit;

Then on the form page:

session_start();
if (!empty($_SESSION['flash'])) { echo $_SESSION['flash']; unset($_SESSION['flash']); }

Troubleshooting checklist: search all generated files for data.htm or MM_redirectTo; confirm the form’s action points to the correct PHP URL; make sure the form page is served via HTTP from a PHP-enabled server (not opened as a local .htm file); avoid any output (including BOM/whitespace) before calling header(); and guard redirects so they only run after a successful insert to prevent redirect loops.

Recommended Answers

All 3 Replies

What does the action attribute of the form - tag say?

Michael

yes, check that; otherwise, just use header() function to redirect to desired page

A script can call itself by: $PHP_SELF (v4) or _SERVER (v5).

To make it happen in HTML, you simply need to add a statement like:

<form action="_SERVER" method="post">

Make sure you use the appropriate conditional so that the script does not get in a loop, i.e. if ($safe_to_proceed) { ... }. Similary if you wish to call your $PHP_SELF script direct from the script itself then we're talking recursion. So be forewarned that recursiuon is great but best used ONLY on simple tight algorithms.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.