PDA

View Full Version : query > insert multiple records question


heathmont
12-14-02, 19:07
what values are passed through to the processing of aform. inparticularly, the amtpaid$userid bit, is it just the number or does this mean amtpaiduser1 = 2080 (if that is the entered number).





<tr>
<td width=10>&nbsp;</td>
<td><?= $userid ?></td>
<td><?= $rentamt ?></td>
<td><input size="10" maxlength="10" type="text" value="0" name="amtpaid<?= $userID ?>"></td>
<td><input size="10" maxlength="10" type="text" value="4" name="currentperiod<?= $userID ?>"></td>

</tr>





the thing is, from the above example, there are 4 sets of data I want to add to the recordset.

plus I need to calculate a $balance figure before i insert the data

the $balance figure = houserentamt - amtpaid (so if someone hasn't paid anything there $balance = -(their own)rentamt.

do i calculate this now, or in the form processing part.

also

my $query2 in the form processing part is:




$query = "INSERT INTO rent_transaction ( id, userid, currentperiod, amtpaid, balance) VALUES ('null', '$userid', '$currentperiod', '$amtpaid', '$balance')";




so this is where i am stuck, as i am not sure how much data is being passed through from the form, or how to work out the $balance figure.

so for instance, as my end result i need something like this being generated:




INSERT INTO rent_transaction ( id, userid, currentperiod, amtpaid, balance) VALUES
('null', 'user1', '4', '2080', '1516'),
('null', 'user2', '4', '0', '-563'),
('null', 'user3', '4', '0', '-455'),
('null', 'user4', '4', '0', '-498')







any ideas?

patrickhenry
12-24-02, 15:30
have you figured it out yet - its been some time since you posted - and I just now joined the forum.

It looks like you are just now trying to learn to implement PHP - am I right?

bcyde
12-26-02, 11:54
Well not sure if you worked through your problems or not, but it sounds like you are asking how to process form data. If your forms are submitted via the post method then you can access all your variables on your form processing page (after the form has been submitted) via $_POST['varname'], so in your case on your form processing page you'd have:

$balance figure = $houserentamt - $_POST['amtpaid'];
(not sure where $houserentamt comes from I'm assuming it wasn't from the form)

If you're not using the post method with your forms (when the variable names and values get appended to the URL when you submit them) use $_GET['varname'] like:

$balance figure = $houserentamt - $_GET['amtpaid'];

Hope this helps.
-b