title: Using $_POST in While PHP Question
body: <p>I'm trying get some information via $_POST in PHP, basically at the moment i'm using this:</p>
  
  <pre><code>$item_name1 = $_POST['item_name1']; 
  $item_name2 = $_POST['item_name2']; 
  $item_name3 = $_POST['item_name3']; 
  $item_name4 = $_POST['item_name4'];
  </code></pre>
  
  <p>I want to insert each of the item names in a table field with mysql so i'm trying to experiment with the while php loop so i dont have lots of $item_name variables:</p>
  
  <pre><code>$number_of_items = $_POST['num_cart_items']; 
  
  $i=1;
  while($i&lt;=$number_of_items)
    {  
      $test = $_POST['item_name'. $i'']; 
      $i++;
    }
  </code></pre>
  
  <p>The above code fails, its pretty tricky to explain but the code should find all the item_name $_POST and make it as a variable for mysql insertion.</p>
  
  <p>The $_POST['num_cart_items'] is the total number of items.</p>
  
  <p>The code is for a PayPal IPN listener for a shopping cart that is underway.</p>
  
  <p>Help appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>I have this further up the document which i just realised:</p>
  
  <pre><code>$req = 'cmd=_notify-validate';
  foreach ($_POST as $key =&gt; $value) {
      $value = urlencode(stripslashes($value));
      $req .= "&amp;$key=$value";
  }
  </code></pre>
  
  <p>How can i insert $_POST['item_name1'], $_POST['item_name2'] as a variable for mysql insertion?</p>