Skip to main content
dhoviss
Participant
June 30, 2009
Answered

Post form to mySQL and then to email not working after insert

  • June 30, 2009
  • 1 reply
  • 1852 views

I am using the Spry framework to validate some fields in a form, and then inserting the entire forms data into a database (with no problems). I then want to send an email with a few fields from the form submission.  Normally this works fine in PHP mail code that I have, BUT after adding the spry validation or after adding the after insert goto section, the PHP mail code no longer gets the post data from the form.

Any ideas what might cause the loss of the post variables from the form?

thanks!

-Daniel Hoviss

This topic has been closed for replies.
Correct answer David_Powers

Normally the form sends the data to the processing page, I am not explicitly passing any form variables.

Like so

<form action="processor.php" method="post" enctype="application/x-www-form-urlencoded" name="ContactForm" />

  <input name="realname" type="text" size="40" maxlength="80">

  <input type="submit" value="Send Comment">

</form>

Actually, you are passing the form variables explicitly. That's what submitting a form does.

When you submit a form, the variables are passed to the next page through either the GET method or the POST method. That's why you can access them using $_POST or $_GET. The variables exist only from one page to the next. As soon as you redirect the user to another page, the values are destroyed. The Dreamweaver code $insertGoTo uses the header() function to redirect the user to another page. That's why your variables are no longer available.

The simple way around this is to add the email script immediately before the code that redirects the user. You can either put the email script directly in the same page, or use a PHP include.

1 reply

Participating Frequently
June 30, 2009

Is the email script on the same page as the insert script, or on a different page? If it's a different page, how are you passing the data along to this page?

dhoviss
dhovissAuthor
Participant
June 30, 2009

I post to a seperate file, after inserting in the database. I do not think this is spry framework related, but Dreamweaver goto code related.

I have tested other forms with the spry validation and they are fine, it is only when I add the insert to mySQL that the form data gets lost.

Normally the form sends the data to the processing page, I am not explicitly passing any form variables.

Like so

<form action="processor.php" method="post" enctype="application/x-www-form-urlencoded" name="ContactForm" />

  <input name="realname" type="text" size="40" maxlength="80">

  <input type="submit" value="Send Comment">

</form>

Then on the processing page I can do stuff.

Like this:

Thank you, <?php echo $_POST["realname"]; ?>
        <p>We have received your comment and hope you enjoyed visiting our site.

But with the Insertgoto after inserting data the above code produces no realname output.

I think on the form page I need to do something different.

$insertGoTo = "processor.php";

Perhaps I need to pass the form variables along here?

If so how can I pass a multitude of form fields?

-Daniel Hoviss

David_Powers
David_PowersCorrect answer
Inspiring
June 30, 2009

Normally the form sends the data to the processing page, I am not explicitly passing any form variables.

Like so

<form action="processor.php" method="post" enctype="application/x-www-form-urlencoded" name="ContactForm" />

  <input name="realname" type="text" size="40" maxlength="80">

  <input type="submit" value="Send Comment">

</form>

Actually, you are passing the form variables explicitly. That's what submitting a form does.

When you submit a form, the variables are passed to the next page through either the GET method or the POST method. That's why you can access them using $_POST or $_GET. The variables exist only from one page to the next. As soon as you redirect the user to another page, the values are destroyed. The Dreamweaver code $insertGoTo uses the header() function to redirect the user to another page. That's why your variables are no longer available.

The simple way around this is to add the email script immediately before the code that redirects the user. You can either put the email script directly in the same page, or use a PHP include.