-2

I have a site where I make a payment, a bill is created through it, but the problem is that I can not use $ _POST twice in one, and this example:

    <?  if (isset($_POST['submit'])) { ?>
        <form action="" method="POST" >
              <input name="invoice" value="" type="text" />
              <input name="pay" value="Pay Now" type="submit" />
        </form>
<? }   if (isset($_POST['pay'])) {
        // MY QUERY HERE
        // HEADERS HERE
} else { ?>
<form action="" method="POST" >
    <input name="info" value="" type="text" />
    <input name="submit" value="Submit" type="submit" />
</form>  
<?  } ?>
  • Look at your PHP Error log, this just has to be generating compile errors – RiggsFolly Jul 15 '18 at 00:31
  • OR add some [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Jul 15 '18 at 00:31

2 Answers2

0

Try this.

Kindly check the code for comment.

<?
  if (isset($_POST['submit'])) {
    $info = $_POST['info'];
   // use echo to display second form
   echo '
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
      <!-- // Note the action value, it's for post back. This allow you to post back to the current page -->
      <!-- This is to keep the record passed from the first form -->
      <input name="info" value="'. $info .'" type="hidden" />
      <input name="invoice" value="" type="text" />
      <input name="pay" value="Pay Now" type="submit" />
    </form>';
  } else if (isset($_POST['pay'])) {

    // MY QUERY HERE

  } else {
    // Note the action value, it's for post back. This allow you to post back to the current page
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
       <input name="info" value="" type="text" />
       <input name="submit" value="Submit" type="submit" />
    </form>
  }
?>
-1

Not the prettiest way to do this but to achieve your result try this...

<?php if (isset($_POST['submit'])) { ?>
    <form action="" method="POST" >
        <input name="invoice" value="" type="text" />
        <input name="pay" value="Pay Now" type="submit" />
    </form>
<?php } elseif (isset($_POST['pay'])) { 

    // Perform query here

} else { ?>
    <form action="" method="POST" >
        <input name="info" value="" type="text" />
        <input name="submit" value="Submit" type="submit" />
    </form>
<?php } ?>
Simon K
  • 1,503
  • 1
  • 8
  • 10