S
S
sunnyrio2018-04-01 21:11:40
PHP
sunnyrio, 2018-04-01 21:11:40

Why doesn't else work?

Why doesn't the fool message appear when submitting an empty form?

<html>
  <head>
  </head>
  <body>
    <h1>
      Добавление нового пользователя
    </h1>
    <form method="post" action="adduser.php">
      <p>
        Введите Имя:
        <input type="text" name="name" size="30">
      </p>
      <p>
        Введите Фамилию:
        <input type="text" name="surname" size="30">
      </p>
      <input type="submit">
    </form>
  </body>
</html>

adduser.php:
<?php
  if (isset($_POST['name']))
  {
    $name = $_POST['name'];
    echo $name;
  }
  else
  {
    echo "fool";
  }
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zvonok1337, 2018-04-01
@sunnyrio

isset() checks for existence.
Name = '' is always passed in your code.
You can do this: I
recommend using the var_dump function for debugging and checking the states of variables

A
Anton fon Faust, 2018-04-01
@bubandos

Because $_POST['name'] == ''

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question