Input if equals doens't return value

Hi all,
I am just starting to learn php.

I am doing this simple task. User should enter text. if text is “london” it should redirect to wikipedias page about London. Otherwise it should say “wrong name”. It always gives me “wrong name” :(.

Here are my codes:
HTML

    <!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <form action="action.php" method="post">
        <input type="text" name="text">
        <input type="submit" name="text">
    </form>
</body>
</html>

and PHP

<html>
<head><title>Website</title></head>

<body>
<?php

     if ($text == "london") {
        header ("Location: https://en.wikipedia.org/wiki/London");
        exit;
        } else {
        echo "wrong name";
        }
?>
</body>
    </html>

Thank you very much in advance.

The form data will be in $_POST['text'] Once upon a time, the variable $text would have worked, but this feature was removed from php in 2012.

Note: since you have named the submit button the same name as the text input field, and it comes after the actual input field, its value will be what you receive. Make sure you name fields uniquely and since the code isn’t using the submit field value, just leave its name attribute out.

Thanks a lot. I deleted submit name
and did this:
if ($_POST[‘text’] === “london”) {

but still it doesn’t redirects to the wikipedia page :frowning: now just blank page appears after submiting “london”

Most likely because you are outputting characters (html markup) prior to the header() redirect. Do you have php’s error_reporting set to E_ALL and display_errors set to ON, in the php.ini on your system, so that php would help you by reporting and displaying all the errors it detects? Stop and start your web server after making any change to the php.ini and confirm that the settings actually got changed to those values by putting a phpinfo(); statement into a .php script file.

Sponsor our Newsletter | Privacy Policy | Terms of Service