0

i am watching tutorials on PHP, and in the video there is this code:

$cntr = 1;
$item = 'dummy';

while(!empty($item))
{
    $item_html_name = 'item'.$cntr;
    $item = $_POST[$item_html_name];

    if (!empty($item))
    {
        print "Item: ".$item."<br>";
        $cntr++;
    }
}

When i try the code, i get an error "Notice: Undefined index: item1"

here is a screenshot of the video:

enter image description here

or it may be because of the different PHP versions?

html are also the same:

<form action="code1.php" method="post">
    <p>1  <input type="text" name="item1" size="30"></p>
    <p>2  <input type="text" name="item2" size="30"></p>
    <p>3  <input type="text" name="item3" size="30"></p>
<input type="submit" value="submit">
Alexandr
  • 921
  • 7
  • 16
  • 1
    bad tutorial use ` ` then loop the array –  May 11 '16 at 21:04
  • it still doesnt answer my question, but thanks anyway – Alexandr May 11 '16 at 21:06
  • is there a check for a post actually being made before the loop? –  May 11 '16 at 21:09
  • No, there wasn't any in the video, but I tried whit and whiteout making variable for the post. Nothing changed. I have tried many variations, but nothing worked, it drives me crazy. – Alexandr May 11 '16 at 21:14
  • on first load there is no post ($_POST) so you will get an error –  May 11 '16 at 21:16

0 Answers0