0
<form method="POST" action="<?php print $_SERVER["PHP_SELF"]; ?>">
    <p><input type="text" name = "word"></p>
    <p><input type="submit" name="Submit" value="Submit"></p>
    <?php 
    $i = $_POST['word'];
        echo strrev($i);
    ?>

gives me this error: Notice: Undefined index: word in C:\wamp\www\php\reverse.php on line 6 is there a solution?

jelle woord
  • 193
  • 2
  • 16
  • its telling you that `$_POST['word']` doest exist. Should it always, or is it optional? – atoms Nov 21 '16 at 10:15

2 Answers2

0

You can handle this error as followed:

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

    echo strrev($_POST['world']);

}

If $_POST['world'] doesn't exist the code wont be run

atoms
  • 2,993
  • 2
  • 22
  • 43
0

$_POST['word'] is not defined so use isset

    <form method="POST" action="<?php print $_SERVER["PHP_SELF"]; ?>">
    <p><input type="text" name = "word"></p>
    <p><input type="submit" name="Submit" value="Submit"></p>
    <?php 
    if(isset($_POST['word']))
    {
      $i = $_POST['word'];
        echo strrev($i);
    }

    ?>
Dave
  • 3,073
  • 7
  • 20
  • 33