-2
<form action="opublikuj/index.php" method="post">
        <div class="title">
          <label for="title">Tytuł</label>
          <input type="text" name="titleInput" id="title"/>
        </div>

        <div class="description">
          <label for="description">Opis</label>
          <textarea
            name="descriptionTxtArea"
            id="description"
            cols="21"
            rows="10"
          ></textarea>
        </div>
</form>

opublikuj/index.php:

<?php
$opis = $_POST['description'];
$tytul = $_POST['title'];
echo $tytul."<br>";
echo $opis."<br>";
?>

it gives me an error: Warning: Undefined array key "title" on line 3 but description works perfectly. I tried using id instead of name in PHP but it is still the same.

  • `titleInput` != `title`. So... `$_POST['titleInput'];` is what you need, because of `name="titleInput"`. It's not rocket science...the name in the form must match the name you search for in PHP $_POST. (`id` has nothing to do with it, because that value is not submitted to PHP). Read https://developer.mozilla.org/en-US/docs/Learn/Forms/Your_first_form#sending_form_data_to_your_web_server and https://www.php.net/manual/en/tutorial.forms.php if you've forgotten the basics of HTML forms. – ADyson Aug 10 '23 at 18:32
  • The name of the input is `titleInput`, not `title`. Only the name attribute gets passed on the form, not the id. – aynber Aug 10 '23 at 18:33
  • P.S. It's also impossible that `$_POST['description'];` will find the form field with `name="descriptionTxtArea"`. You must be mistaken about that (when you said "description works perfectly"), or at least you must have tested it with different code than you've shown here. – ADyson Aug 10 '23 at 18:35

1 Answers1

1

You have to select th name property from the $_POST, not id.

Try:

<?php
$opis = $_POST['descriptionTxtArea'];
$tytul = $_POST['titleInput'];
echo $tytul."<br>";
echo $opis."<br>";
?>