首页 > 解决方案 > $_POST 返回空我该如何解决这个错误?

问题描述

我无法在脚本中检索我需要的值,这是我的代码:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>LUCAS</title>
  </head>
  <body>
    <h1>MD5 CRACKER EXERCISE:</h1>
    <p>crack the hash value into a 4 digit pin:</p>
    <form action="index.php" method="get">
      <input type="text" name='md5' size="40" value="">
      <input type="submit" name='submit' value="crack">
    </form>
<?php


  $pin = NULL;
  $hashedValue = $_GET['md5'];
  echo "Debug Output: ";

  echo $_POST['submit'];

if (isset($_POST['submit'])){
    echo "string";
    for ($i = 0; $i <= 9999; $i ++){
      if ($i < 15){
        echo hash("md5",strval($i));
      };

      if (hash("md5",strval($i)) == hash("md5",strval($hashedValue))) {
        echo $i." correct value";
        break;
      };

    };
  };

  $result = $pin ?? "not found";
  echo "<br><br>PIN:".$result;

 ?>

  </body>
</html>

我得到以下信息:

“错误通知:未定义索引:在第 21 行的 /Applications/MAMP/htdocs/firstPage/index.php 中提交”

这是第 21 行:

 echo $_POST['submit'];

我在这里做错了什么?我设置名称试图在单引号和双引号之间切换,但似乎没有任何效果..

提前谢谢你的答案..

标签: phphtml

解决方案


推荐阅读