php - Forms & Posting - Multiple Data -


so looking @ other posts on site , came across code below (edit of code) works apart when submit error code of: notice: undefined index: id in /customers/0/2/e/richardbrown.name/httpd.www/debt/payment_process.php on line 17 each result.

<form method="post" action="payment_process.php"> <table border="0">'; $stmt = $db->query("select * debt_accounts left join debt_companies on accounts_company=companies_id accounts_amount > 0 order accounts_company asc");  while($row = $stmt->fetch(pdo::fetch_assoc)){ echo'<tr> <td width="200" align="left"><input type="text" name="payment[][id]" value="'.$row['accounts_id'].'" /></td> <td width="100" align="right"><input type="text" name="payment[][amount]"  value="25.00" /></td> </tr>';                   }     echo'</table><br /> <br /><input type="submit" /></form>   if ( isset( $_post['payment'] ) ) {     echo '<table>';     foreach ( $_post['payment'] $diam )     {         echo '<tr>';         echo '  <td>', $diam['id'], '</td>';         echo '  <td>', $diam['amount'], '</td>';         echo '</tr>';     }     echo '</table>'; } 

change line form element:

name="payment_amount" 

to array:

name="payment_amount[]" 

then, modify foreach read as:

foreach ($_post['payment_amount'] $value) {   echo $value . "<br>"; }  
  • you using wrong post array => name="payment_id[]"

to add them up, should want that, use:

foreach ($_post['payment_amount'] $value) {     echo $value . "<br>";     $total += $value;   }      echo $total;  

or

$total = array_sum($_post['payment_amount']); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -