RCDAWebmaster
RCDAWebmaster

Reputation: 325

php session variables not persisting between pages

I have a web form that was emailing itself multiple times if someone clicked the submit button more than once.

In the form, I added:

$_SESSION["EmailSent"] = 0;

On the processing page I added:

if ($_SESSION["EmailSent"] == 0){
    $_SESSION["EmailSent"] = 1;
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } 
    else {
        //echo 'Message has been sent';
    }
}

On the processing page, I'm getting the error: PHP Notice: Undefined index: EmailSent

I added session_start( ) to the top of the pages. The weird thing is that the email is still being sent and not stopped when the page encounters the error.

Upvotes: 0

Views: 62

Answers (1)

RCDAWebmaster
RCDAWebmaster

Reputation: 325

The error was because of the thing between the seat and Keyboard. Me.

I added session_start( ) to the top of each page through a Dreamweaver template. The problem is that the processing page is not tied to the template and didn't have the code. I added it to the page and it's working. the form now submits only once.

Upvotes: 1

Related Questions