数据未发布。请检查我的代码

时间:2019-04-22 14:41:54

标签: php mysql

我正在尝试从HTML表单发布脚本中显示的值。我已经确认表格已成功提交数据。但是,当我尝试测试使用isset()脚本提交的值时,我什么也没得到。我还发布了我的函数,以查看是否在此出错。

 if(isset($_POST['submit']) && !empty($_POST['submit'])) {

    function test_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
    }


        // require_once('mystuff/functions.php');

        echo $to_account = test_input($_POST['to_account']);
        echo $to_email = test_input($_POST['to_email']);
        echo $amount = test_input($_POST['amount']);
        echo $pin = test_input($_POST['pin']);



    } else {
        echo "Probably the data was not submitted";
    }



 <div class="container">
      <h2>Transfer:</h2>
      <form action="transCtrl.php" method="POST">
        <div class="form-group">
          <label for="to_account">To Account</label>
          <input type="text" class="form-control" id="to_account" name="to_account" required pattern="[A-Z0-9]{13}">
        </div>
        <div class="form-group">
          <label for="to_email">To Email:</label>
          <input type="email" class="form-control" id="to_email" name="to_email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" required>
        </div>
        <div class="form-group">
          <label for="amount">Amount</label>
          <input type="number" class="form-control" id="amount" name="amount" required min="100">
        </div>
        <div class="form-group">
          <label for="pin">8 Digit PIN</label>
          <input type="text" class="form-control" id="pin" name="pin" pattern="[0-9]{8}" required>
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
    </div>

1 个答案:

答案 0 :(得分:1)

相反

 if(isset($_POST['submit']) && !empty($_POST['submit'])) {

使用此:

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

您没有$ _POST ['submit']变量。