Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

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

Explorer ,
Jun 29, 2009 Jun 29, 2009

Copy link to clipboard

Copied

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

TOPICS
Server side applications

Views

1.7K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2009 Jun 29, 2009

Copy link to clipboard

Copied

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?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

Thanks - that works like a charm.

I have moved the error testing and PHP email code into the form page, before the insertgoto code line.

What I ment by "explicit" was that I am not creating session variables, or passing variables on the url to the next page.

I am aware that a post or get passes the variables, and that they are destroyed.

What I did not get was that the code below somehow destroys the variables, though it was clear something was happening.

  $insertGoTo = "processor.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }

Now if we could only get some leverage to enhance the spry validation code so it performed useful validation of comment fields, and really validated email addresses corectly I would not have to add extra code..

Thanks again David - 10 points.

-Daniel Hoviss

Dosolutions Inc.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 30, 2009 Jun 30, 2009

Copy link to clipboard

Copied

LATEST

What I did not get was that the code below somehow destroys the variables, though it was clear something was happening.

  $insertGoTo = "processor.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }

It doesn't. You have misunderstood what I said (or maybe I wasn't clear enough). It's going to the third page that destroys the variables.

When you submit the form, the variables are created, and can be used in the second page (the page that the form is submitted to). However, after the code you have posted here, Dreamweaver uses something like this:

header("Location: $insertGoTo");

That sends the visitor to a third page. It's in that process that the variables are destroyed. As far as the browser is concerned, the form is page 1, the processing script is page 2, the redirect page is page 3. The fact that you never see the page that processes everything is irrelevant.

Now if we could only get some leverage to enhance the spry validation code so it performed useful validation of comment fields, and really validated email addresses corectly I would not have to add extra code...

Spry or any JavaScript validation is only done as a courtesy to the visitor. You cannot omit the server-side validation, because it's easy for malicious users to turn off JavaScript and fill your database with garbage or worse.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines