user2467357
user2467357

Reputation: 1

PHP HTML Form can't read variables posted back on itself

I've not done any coding in a while, but needed a quick way to send an email to a few people at a time with using two variables. Should be simple, but I have no idea why this isn't working.

Thanks in advance.

    <?php

    if(!empty($POST['update']))
     {
echo 'it works!';
     }
    else
     {
    ?>

<h1>Order Confirmation</h1>
<form method="post" action="order-confirmation.php" name="update">
<table>
<tr>
<td>Account Number</td>
    <td>Consignment Number</td>
</tr>
<tr>
<td><input type="text" name="accno" value=""/></td>
<td><input type="text" name="conno" value=""/></td>
</tr>
<tr>
<td><input type="submit" name="submit" action="order-confirmation.php"/></td>
</tr>
</table>

</form>
<?php
}
?>

Upvotes: 0

Views: 900

Answers (3)

Nikola R.
Nikola R.

Reputation: 1173

You do not have input field called "update".

You must also replace $POST with $_POST and add an <input type="hidden" name="update" value="1" /> to your form.

type="submit" does not need action attribute because you already have defined action in your <form>.

Upvotes: 2

Hawili
Hawili

Reputation: 1659

I usually use something like this (anything with // before mean comment, not executable code)

//Request method detect that POST is used not GET which mean the form is submitted

if ($_SERVER['REQUEST_METHOD'] == 'POST) {

  // This condition detect that the input with name "submit" is pressed, you can 
  // add multiple submit buttons and each with different value, then just do 
  // equality check to specify the actions

  if ($_POST['submit']) {
      echo 'it works!';   
  }
}

Upvotes: 0

Alice
Alice

Reputation: 701

It should be

$_POST

Instead of

$POST

Also, you want it to be $_POST['submit'] instead of update.

Upvotes: 3

Related Questions