php post method not working right

时间:2016-02-03 04:24:37

标签: php

<html>
<head>
</head>
<body>
<form action="TakeTwo.php" method="post">
   <input type="text" name="trail" placeholder="Enter Test Here">
   <input type="submit" name="Submit">
</form>
<?php
if (isset($_POST['Submit'])) {

   $k = $_POST['trial'];

   echo $k;
}
?>
</body>
</html>

for some reason it gives me a error that says this:

Notice: Undefined index: trial in C:\xampp\htdocs\KyleLongrich.com\TakeTwo.php on line 18

Any help would be awesome. Also line 18 is referring to to echo $k;

4 个答案:

答案 0 :(得分:2)

Spelling mistake (Trail instead of trial). Check this.

<html>  
<form action="TakeTwo.php" method="post">
    <input type="text" name="trail" placeholder="Enter Test Here">
    <input type="submit" name="Submit">


<?php

if(isset($_POST['Submit']))
{

$k = $_POST['trail'];

echo $k;

}

?>

答案 1 :(得分:1)

You have spell mistake for trial in your form.

Replace this :

<input type="text" name="trail" placeholder="Enter Test Here">

With this :

<input type="text" name="trial" placeholder="Enter Test Here">

答案 2 :(得分:0)

1

  action = "TakeTwo.php" change to <?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>

2

  if(isset($_POST['Submit'])) to 
  if (!empty($_POST))

这样做会很好。

答案 3 :(得分:0)

拼写错误

替换此

<input type="text" name="trail" placeholder="Enter Test Here">

通过这个

<input type="text" name="trial" placeholder="Enter Test Here">