showForm('paypal', $posted); }?>Exibit #2 - paypal preconfirmation form.PayPal Pre-confirmation Information # Registration ID Name Age Group Student Discount Requested Registration Charge $ setQuery($query);$t_rows = $db->loadRowList();foreach ( $t_rows as $t_row ) {$i++;switch ($t_row[4]) { case "U6": $amt=6; break; case "U7": $amt=7; break; case "U8": $amt=8; break; case "U9": $amt=9; break; case "U10": $amt=10; break; case "U11": $amt=11; break; case "U12": $amt=12; break; case "U13": $amt=13; break; case "U14": $amt=14; break; case "U15": $amt=15; break; case "U16": $amt=16; break; case "U17": $amt=17; break; case "U18": $amt=18; break; case "U19/21": $amt=21; case "All Age": $amt=25; break; case "Prem-League": $amt=30; break; case "Over35": $amt=35; break; }$amtFmtd = number_format($amt,2);$sTotCalc = $sTotal + $amt;$sTotal = number_format($sTotCalc,2);?> - ';print ''; }//penalties/discounts & total variables here$earlyLate='early';$early=-0.10;$late10=0.10;$late20=0.20;$gTotal=0.00; //penalty-discount calcs hereif ($earlyLate=='late10'){$pdDesc='10% Late Fee';$gTotCalc = $sTotal*(1+$late10);$gTotal = number_format($gTotCalc,2);$pdFeeCalc = $sTotal*$late10;$pdFee= number_format($pdFeeCalc,2);}elseif($earlyLate=='late20'){$gTotCalc = $sTotal*(1+$late20);$gTotal = number_format($gTotCalc,2);$pdDesc='20% Late Registration Fee';$pdFeeCalc = $sTotal*$late20;$pdFee= number_format($pdFeeCalc,2);}elseif($earlyLate=='early'){$gTotCalc = $sTotal*(1+$early);$gTotal = number_format($gTotCalc,2);//$gTotal = $sTotal*(1-$early);$pdDesc='10% Early Registration Discount';$pdFeeCalc = $sTotal*$early;$pdFee= number_format($pdFeeCalc,2);}else$gTotal = number_format($sTotal,2);//p-d item creation for paypal$itemPD = 'item_'.($i+1);$feeAmt = "amount_".($i+1);print '';print ''.$itemPD.$pdDesc.''; print ''.$feeAmt.$pdFee.'';print '';print '';print ''; ?> Subtotal Extra Charges Total //other variable for paypal submission" />"> CF not retrieving all records in a query - Forums

Forums

CF not retrieving all records in a query

ajw3208 16 Jun, 2009
Hi all,

We have an intertesting problem here, where the submit from the previous form works and the d/base write is committed successfuly, however the next form which should retrive the previous information returns n-1 number of records (1 less than are in the d/base). It almost as if the form looking up the information after submission has started its processing before the final write commit has been completed in the d/base (mySQL)

Details:

This problem here is that not all the records are being retrieved by the query when the variable value ($regoNum), which is retrived from the $_POST array is used in the query. It works fine (i.e correct number of records are retrieved) if the variable $regoNum is hardcode to a value. (see screen shot attached. there were 2 records in the d/base and 2 are shown and yes there is a prob with the calculation logic but I'll fix that later :? )
[attachment=0]paypalpreconf.jpg[/attachment]

As you can see from the code in Exibit#2 , $reogNum is also printed out to ensure I could retrieve it, and this works OK.

The sympotoms are as follows:

previous form (regoform4) submits and writes successfuly to the d/base. This form has the code in exibit #1 in the "On Submit code - after sending email:" section. The action is successful and the paypal preconfirmation form is shown

the issue is that the paypal preconfirmation form- in Exibit #2 - uses the variable $regoNum as the selector for which records to return.

If there is only one record that macthes the variable, no records are returned. If there are multiple records that match the variable value, then n-1 records are returned. (i.e 1 less than the record count in the d/base).

Can offer any advice here?

If you need to, you can test the process by going to http://test.wphcfc.net.au and clicking on online-registration. By clicking on the all Reports menu item (uses CC), you can see the registrations that are in the d/base.

Thanks

aj

Exibit #1
<?php
$action = JRequest::getString('rf4SBtn');
if (strcasecmp($action, 'Proceed to Payment') != 0) {
     $MyForm->showForm('regoform1', $posted);
}
else {
    $MyForm->showForm('paypal', $posted); 
}
?>


Exibit #2 - paypal preconfirmation form.
<H3>PayPal Pre-confirmation Information</H3>
<br>
<table style="text-align: left; width: 100%;" border="0" cellpadding="1" cellspacing="2">
<tbody>
<tr>
  <td style="width: 3%;text-align: center;">#</td>
  <td style="width: 7%;text-align: center;">Registration ID</td>
  <td style="width: 7%;text-align: center;">Name</td>
  <td style="width: 7%;text-align: center;">Age Group</td>
  <td style="width: 7%;text-align: center;">Student Discount Requested</td>
  <td style="width: 7%;text-align: center;">Registration Charge $</td>           
</tr>
<tr>
	<td colspan=6><hr>
	</td>
</tr>
<?php
$i=0;
$sTotal=0;
//dbase stuff here, get and render
//$regoNum = $_POST['playerRegNum'];
$regoNum = '20090615-213';
print $regoNum;
$db =& JFactory::getDBO();
$tablename = 'jos_chronoforms_wphcfc_regoinfo';
$query = 'SELECT playerRegNum,playerRegNumCtr,playerFirstname,playerSurname,playerRegoAgeGrp,playerStudent FROM jos_chronoforms_wphcfc_regoinfo WHERE playerRegNum ='.'\''.$regoNum.'\''.' ORDER BY jos_chronoforms_wphcfc_regoinfo.playerRegNumCtr ASC';
$db->setQuery($query);
$t_rows = $db->loadRowList();
foreach ( $t_rows as $t_row ) {
$i++;
switch ($t_row[4]) {
    case "U6":
        $amt=6;
        break;
    case "U7":
        $amt=7;
        break;
    case "U8":
        $amt=8;
        break;
    case "U9":
        $amt=9;
        break;
    case "U10":
        $amt=10;
        break;
    case "U11":
        $amt=11;
        break;
    case "U12":
        $amt=12;
        break;
    case "U13":
        $amt=13;
        break;
    case "U14":
        $amt=14;
        break;
    case "U15":
        $amt=15;
        break;
    case "U16":
        $amt=16;
        break;
    case "U17":
        $amt=17;
        break;
    case "U18":
        $amt=18;
        break;
    case "U19/21":
        $amt=21;
    case "All Age":
        $amt=25;
        break;
    case "Prem-League":
        $amt=30;
        break;
    case "Over35":
        $amt=35;
        break;      
}
$amtFmtd = number_format($amt,2);
$sTotCalc = $sTotal + $amt;
$sTotal = number_format($sTotCalc,2);
?>
<tr>
	<td style="width: 3%;text-align: center;"><?echo $i?></td>	
	<td style="width: 7%;text-align: center;"><?echo $t_row[0]?>-<?echo $t_row[1]?></td>
	<td style="width: 7%;text-align: center;"><?echo $t_row[2]?> <?echo $t_row[3]?></td>
	<td style="width: 7%;text-align: center;"><?echo $t_row[4]?></td>
 	<td style="width: 7%;text-align: center;"><?echo $t_row[5]?></td>
 	<td style="width: 7%;text-align: center;"><?echo $amtFmtd?></td>
</tr>
<?
$item = "item_".$i;
$amount = "amount_".$i;

print '<input type="hidden" name="'.$item.'" value="'.$t_row[0].'-'.$t_row[1].', '.$t_row[2].' '.$t_row[3].', Agegrp: '.$t_row[4].'">';
print '<input type="hidden" name="'.$amount.'" value="'.$amtFmtd.'">';
       }
//penalties/discounts & total variables here
$earlyLate='early';
$early=-0.10;
$late10=0.10;
$late20=0.20;
$gTotal=0.00;     

//penalty-discount calcs here
if ($earlyLate=='late10')
{
$pdDesc='10% Late Fee';
$gTotCalc = $sTotal*(1+$late10);
$gTotal = number_format($gTotCalc,2);
$pdFeeCalc = $sTotal*$late10;
$pdFee= number_format($pdFeeCalc,2);
}
elseif($earlyLate=='late20')
{
$gTotCalc = $sTotal*(1+$late20);
$gTotal = number_format($gTotCalc,2);
$pdDesc='20% Late Registration Fee';
$pdFeeCalc = $sTotal*$late20;
$pdFee= number_format($pdFeeCalc,2);
}
elseif($earlyLate=='early')
{
$gTotCalc = $sTotal*(1+$early);
$gTotal = number_format($gTotCalc,2);
//$gTotal = $sTotal*(1-$early);
$pdDesc='10% Early Registration Discount';
$pdFeeCalc = $sTotal*$early;
$pdFee= number_format($pdFeeCalc,2);
}
else
$gTotal = number_format($sTotal,2);
//p-d item creation for paypal
$itemPD = 'item_'.($i+1);
$feeAmt = "amount_".($i+1);
print '<br>';
print '<p>'.$itemPD.$pdDesc.'</p>'; 
print '<p>'.$feeAmt.$pdFee.'</p>';
print '<br>';
print '<input type="hidden" name="'.$itemPD.'" value="'.$pdDesc.' '.$pdType.'">';
print '<input type="hidden" name="'.$feeAmt.'" value="'.$pdFee.'">';   
?>
<tr>
	<td colspan=6><hr>
	</td>
</tr>
<tr>
	<td colspan=4></td><td align="center"><b><i>Subtotal</i></b></td><td align="center"><?php echo $sTotal?>
	</td>
</tr>
<tr>
	<td colspan=3></td><td align="center"><i>Extra Charges</i></td><td align="center"><?php echo $pdDesc?></td><td align="center"><?php echo $pdFee?>
	</td>
</tr>
<tr>
		<td colspan=4></td><td colspan=2><hr>
	</td>
</tr>
<tr>
	<td colspan=4></td><td align="center"><b><i>Total</i></b></td><td align="center"><?php echo $gTotal?>
	</td>
</tr>
<tr>
  <td colspan=4></td><td colspan=2><hr>
	</td>
</tr>
<tr>
  <td colspan=4></td><td colspan=2 align="center"><br>
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
	</td>
</tr>
</tbody>
</table>

//other variable for paypal submission
<input type="hidden" name="playerRegNum" value="<?php echo $_POST['playerRegNum'];?>" />
<input type="hidden" name="currencyCode" value="AUD" />
<input type="hidden" name="countryCode" value="AU" />
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="seller_1243319834_biz@optusnet.com.au">
<input type="hidden" name="currency_code" value="AUD">
<input type="hidden" name="rm" value="2">
<input type='hidden' name='quantity_1' value='1'>
<input type="hidden" name="cancel_return" value="http://test.wphcfc.net.au/index.php?option=com_chronocontact&chronoformname=paypalfail">
<input type="hidden" name="return" value="http://test.wphcfc.net.au/index.php?option=com_chronocontact&chronoformname=paypalok">
GreyHead 16 Jun, 2009
Hi ajw328,

If i understand correctly the problem is that this code
$db =& JFactory::getDBO();
$regoNum = $_POST['playerRegNum'];
//$regoNum = '20090615-213'; //hardcoded test value.
print $regoNum;
$tablename = 'jos_chronoforms_wphcfc_regoinfo';
$query = 'SELECT playerRegNum,playerRegNumCtr,playerFirstname,playerSurname,playerRegoAgeGrp,playerStudent FROM jos_chronoforms_wphcfc_regoinfo WHERE playerRegNum ='.'\''.$regoNum.'\''.' ORDER BY jos_chronoforms_wphcfc_regoinfo.playerRegNumCtr ASC';
$db->setQuery($query);
$t_rows = $db->loadRowList();
foreach ( $t_rows as $t_row ) {
. . .
}
gives a different number of results when $regoNum is supplied as a hard coded number or passed from the previous form.

I don't think that is technically possible - assuming that $regNum gets the same value in both cases then the sql will be identical and will return the same result. I'd suggest that you echo out $query to see exactly what the query is in each case.

That said, I can't work out the quoting for '.'\''.$regoNum.'\''.' and it's possible that something odd is happening here. Try using this for your query
$query = "SELECT `playerRegNum`, `playerRegNumCtr`, `playerFirstname`, `playerSurname`, `playerRegoAgeGrp`, `playerStudent` 
  FROM `#__chronoforms_wphcfc_regoinfo` 
  WHERE `playerRegNum` = '$regoNum' 
  ORDER BY `playerRegNumCtr` ASC; ";
echo '<div>$query: '.print_r($query, true).'</div>';


Bob
ajw3208 17 Jun, 2009
Hi Bob,

Thanks for the feedback. Your analysis of the situation is pretty close. however, I tried your code and it didn't change the outcome (although it is neater code). As you can see from the info below, the output using dynamic and hardwired variables being feed into the query is identical (except for the explict table names).

query Output from dynamic variable
20090616-103
$query: SELECT `playerRegNum`, `playerRegNumCtr`, `playerFirstname`, `playerSurname`, `playerRegoAgeGrp`, `playerStudent` FROM `#__chronoforms_wphcfc_regoinfo` WHERE `playerRegNum` = '20090616-103' ORDER BY `playerRegNumCtr` ASC; 


query output from hardwired variable (using my code not yours)
20090615-213
$query: SELECT playerRegNum,playerRegNumCtr,playerFirstname,playerSurname,playerRegoAgeGrp,playerStudent FROM jos_chronoforms_wphcfc_regoinfo WHERE playerRegNum ='20090615-213' ORDER BY jos_chronoforms_wphcfc_regoinfo.playerRegNumCtr ASC



The problem seems to be manifesting itself in the transition from the previous form. The previous form writes to the dBase correctly. The variable $regoNum is being recovered from the $_POST array correctly but no records are being displayed. If I hardwire the $regoNum into the code it works correctly.

I have been able to confirm that the $regoNum variable is working but it needs a repost/resend to display the record but it is still only recovering n-1 records (I actually end up with a duplicate recordof the one that was created in the rego process). This suggest that the query is either not picking up the first record, or its not being written to the array. This only works when the redirect code from the previous form is used (see original post). The URL shown reflects the previous form, not the paypal form

Interestingly, if I disable the redirect code from regoform 4 and use the std submit url mechanism. The paypal form appears in the url box, but no records are shown and a repost doesn;t work.

thoughts?
ajw3208 17 Jun, 2009
Hi Bob,

Looks like I have found a solution. I believe it was a timing lock issue on the database. I did the following

1. Make the submit write to database BEFORE email. (found in autogen tab). I think the the form still had a lock on the enrtyu (i.e. uncommited write) and the next d/base event (i.e. the select) didn't actually find a record.
2. created fresh empty forms and just copied the code from the old ones into them. I have a suspicion of a corrupted form but I can't prove it.

Having done all this, The select query is now working.

I have anpother question though.

How can we validate dbase activity went as planned? (i.e test, report and perform alt action on failure)

aj
Max_admin 22 Jun, 2009
Hi aj,

you can check the query function returned true or false and get the error from :

$database->getErrorMsg()


Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.