英文:
Undefined array key "title" but in only one input
问题
<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>";
?>
在第3行出现了一个警告:Undefined array key "title",但是description正常工作。我尝试在PHP中使用id而不是name,但结果仍然相同。
英文:
<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.
答案1
得分: 1
你必须从 $_POST
中选择 name
属性,而不是 id
。
尝试:
<?php
$opis = $_POST['descriptionTxtArea'];
$tytul = $_POST['titleInput'];
echo $tytul."<br>";
echo $opis."<br>";
?>
英文:
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>";
?>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论