title: PHP and mysql checkbox insert
body: <p>I am working on a project where i need to  pass values (from a list of products) of multiple checkboxes AND text boxes to a table (new_orders) on the database. </p>
  
  <p>I managed to create the list retrieving the products from the table articles, but i can't insert the products that i choose with  the quantities that i insert to the table new_orders on the database. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>foreach($A_result as $key =&gt; $value) // για χρηση όλων των αντικειμένων του πίνακα A_apotelesma
  {
  
  
  // shows al the products
      echo "&lt;tr&gt; 
                &lt;td align=center&gt;".$j++."&lt;/td&gt;
                &lt;td align=center&gt;".$value['name']."&lt;/td&gt;
                &lt;td align=center&gt;".$value['price']."&lt;/td&gt; ";
  
  echo"&lt;td&gt; // each product has a checkbox and a text box to enter the quantity
  
              &lt;input type=checkbox name=\"article[]\"&gt;&lt;/input&gt;
              &lt;input type=text name='quantity_".$value['id_article']."' size='3' maxlength='2'&gt;
           &lt;/td&gt;";
  
      echo"&lt;td&gt;&lt;input type='hidden' name='id_article' value=".$value['id_article']."&gt;&lt;/td&gt;"; 
      echo"&lt;td&gt;&lt;input type='hidden' name=\"code_user\" value=\"code_user\"&gt;&lt;/td&gt;"; 
  
      echo"&lt;/tr&gt;";
  }
  }
  
  ?&gt;  
  
   // The form above redirects to the insert_order.php page:
  
  
  &lt;?php
  
  include("conn.php");
  
  session_start();
  
  $checkbx=$_POST['article'];
  
  if($_POST['article']){
  
  for($i=0;$i&lt;sizeof($checkbx);$i++){
  
  $quantity=$_POST['quantity_.$id_article'];
  
  $username=$_SESSION['logged_user_username'];
  
  $insert_order_query= "INSERT INTO new_orders (id_article, quantity, username) VALUES (".$id_article.",".$quantity.", '".$username."')";
  //echo $insert_order_query;
  $insert_order=mysql_query($insert_order_query) or die('Error,query failed!!'); 
   if ($insert_order)
       echo '&lt;script language="javascript"&gt;alert("New order created!"); document.location="logged_in_user.php?menu=1";&lt;/script&gt;';
   else
   {
      echo '&lt;script language="javascript"&gt;alert("The order has not been created.")&lt;/script&gt;';
      echo '&lt;script language="javascript"&gt; document.location="logged_in_user.php?menu=1.php"; &lt;/script&gt;';
      exit();
   }
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p>I ALWAYS get the error message.</p>