jelle woord jelle woord - 19 days ago 6
PHP Question

undefined index $_POST PHP_SELF

<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?

Answer

$_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);
    }

    ?>