pass form variable via POST not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

pass form variable via POST not working

Post by jonnyfortis »

what am i missing. got a simple form with an email address that i need passing to another page so i can send a confirmation mail saying we have their email address but the variable is not passing

form

Code: Select all

      <form method="post" name="form2" action="<?php echo $editFormAction; ?>">
        <input type="text" name="maillistEmail" placeholder="email address" class="textox">
        <input type="submit" name="btn2" class="btn" value="SIGNUP">
        <input type="hidden" name="MM_insert" value="form2">
          </div>
        </form>
code

Code: Select all

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO beau_mailist (maillistEmail) VALUES (%s)",
                       GetSQLValueString($_POST['maillistEmail'], "text"));

  mysql_select_db($database_beauSS15, $beauSS15);
  $Result1 = mysql_query($insertSQL, $beauSS15) or die(mysql_error());

  $insertGoTo = "mail-list-thank-you.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
then all i want on the next page mail-list-thank-you.php

$customerEmail = $_POST["maillistEmail"];

then the mail script...
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: pass form variable via POST not working

Post by Celauran »

After processing the form, you're performing a header redirect. That's not a POST request, so $_POST will be an empty array. You could append a query string, use a session, or redirect with a post request instead.
Post Reply