Jump to content

reading an array of $_POST[deposits]


mattjtayl

Recommended Posts

ok I have a question. My forum is setup so it dynamically posts 1 or more direct deposits depending on how many the user enters. The problem is it is only writing the first $POST to mySQL and not the subsequent ones. Do I need to store all the same $_POSTS[same name] in an array or can I do a $_POST[same name] +new_Count.  Can i do this without using arrays, how does the $_POST variables. Look at my psudeo code to see what I mean, the syntax is right at work, but this is the best I can remember at home.

 

here is some psuedo code


[i]Forum code:[/i]

InsertNewRowFunction()
..... code adds another Row to table....

new_count= 0;
each time this function iss called
{
new_count ++
}

table.insertRow
table.insertCell(0)
table.cell.innerHTML = "<select name ='deposit_select" +new_count+" ' id = 'deposit select" +new_count+" 'onchange = insertNewRowfunction()><option>none</option><option>direct deposit</option>"
table.insercell(1)
table.cell.innerHTML = "<input mask ="$######.##" name='deposit_amt"+new_count+ " 'id ='deposit_amt" + new_count+ '>"
table.insertCell(2)
table.cell.innerHTML = "<input name='routeNumber" +new_count " ' id = 'routeNumber"+new_count+" '>"
table.insertCell(3)
table.cell.innerHtML = "<input name ='accNumber" +new_count+ " ' id ='accNumber" +new_count +" '>"

<table>
etc ...
<th>
<tr>
<td>Deposit?</td>
<td>Deposit Amt</td>
<td>Routing Number</td>
<td>account number</td>
</tr>
<tr>
<td> <select name ="deposit_select" id = "deposit select" onchange = insertNewRowfunction()><option>none</option><option>direct deposit</option>
</td>
<td> <input mask ="$######.##" name="deposit_amt" id ="deposit_amt"></td>
<td> <input name"routeNumber" id = "routeNumber"></td>
</td> <input name ="accNumber" id ="accNumber"></td>
</tr>
</select>
</table>

...
[i]php code in a different file[/i]

<?  

open database

$deposit_amt = array()
$deposit_amt = $_POST['deposit_Amt']
$deposit_query = select deposit_amt  from depositsTable 

foreach($deposit_amt as $amount)
{
execute $deposit_query
}


Now this code will only write to mySQL database on the first $_POST['deposit_amt'] all other subsequent 
$_POST['deposit_amt'] are completely ignored.

Link to comment
Share on other sites

You have to use

 

"deposit_Amt[]" in your form (not "deposit_Amt")

 

That way all of your values will go into the array: $_POST['deposit_Amt']

 

use: print_r($deposit_Amt);

 

to see the array.

 

you can pull info from the array by using:

 

$deposit_Amt[0]

$deposit_Amt[1]

$deposit_Amt[2]

$deposit_Amt[3]

 

 

etc etc

etc etc

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.