I encountered a very frustrating bug today (even though it's surely my fault) : I have an html form with several input elements which posts them to a php file. I keep on getting the undefined index error because one of the form element doesn't wanna get posted. Here's my html code (simplified) (/forms/form.php) :
<form action="/php/save.php" method="post">
<table>
<tr>
<td><input type="text" value="" name="SpeechmanWeek1"/></td>
<td><input type="text" value="" name="SpeechmanWeek2"/></td>
<td><input type="text" value="" name="SpeechmanWeek3"/></td>
<td><input type="text" value="" name="SpeechmanWeek4"/></td>
</tr>
<tr>
<td><input type="text" value="" name="ReaderWeek1"/></td>
<td><input type="text" value="" name="ReaderWeek2"/></td>
<td><input type="text" value="" name="ReaderWeek3"/></td>
<td><input type="text" value="" name="ReaderWeek4"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit" name="submit"/></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</form>
Now, here's my php code (simplified too) (/php/save.php) :
<?php
if(isset($_POST['submit'])) {
$SpeechmanWeek1 = $_POST['SpeechmanWeek1'];
$SpeechmanWeek2 = $_POST['SpeechmanWeek2'];
$SpeechmanWeek3 = $_POST['SpeechmanWeek3'];
$SpeechmanWeek4 = $_POST['SpeechmanWeek4'];
// the above code works fine (I get no undefined index error for it)
// but the following code keeps on causing an undefined index notice and I don't get why
$ReaderWeek1 = $_POST['ReaderWeek1'];
$ReaderWeek2 = $_POST['ReaderWeek2'];
$ReaderWeek3 = $_POST['ReaderWeek3'];
$ReaderWeek4 = $_POST['ReaderWeek4'];
}
?>
I keep on getting this error :
Notice: Undefined Index: ReaderWeek1 in /var/www/html/php/save.php
Notice: Undefined Index: ReaderWeek2 in /var/www/html/php/save.php
Notice: Undefined Index: ReaderWeek3 in /var/www/html/php/save.php
Notice: Undefined Index: ReaderWeek4 in /var/www/html/php/save.php
I already had a look at other threads but none actually matched my situation.
Do you have any idea why I get this error and why specific form elements don't get posted while all the others do ?
Thanks in advance for taking the time to answer me.
`Array ( [SpeechmanWeek1] => John [SpeechmanWeek2] => Vincent [SpeechmanWeek3] => Jackson [SpeechmanWeek4] => John [ReaderWeek1] => Rody [ReaderWeek2] => Jackson [ReaderWeek3] => John [ReaderWeek4] => Rody` – Rody Gosset Jun 21 '17 at 06:45