notify.php[/list=1]This application allows a youth group leader to pay for their entire group's admission to our College Days event. This way, he/she doesn't have to enter their credit card information separately for each student.
Each student's name goes into $SESSION['studentnames']. The total count is represented by $SESSION['studentcount'].
confirm.php sends each student as a unique hidden form field to authorize.php, via the following code:
$names = $_SESSION['studentnames'];
for ($i = 0; $i < $_SESSION['studentcount']; $i++)
{
$j = $i + 1;
echo "<input type=\"hidden\" name=\"student$j\" value=\"$names[$i]\" />\n";
}
I know this works, because "View Source" of confirm.php shows the following:
<input type="hidden" name="student1" value="John Smith" />
<input type="hidden" name="student2" value="Jane Doe" />
<input type="hidden" name="student3" value="Lisa Johnson" />
So far, so good. Now we're in authorize.php where the troubles begin. This file uses cURL to send each form field as a URL post to Authorize.net's gateway, using the standard "ampersand fieldname equals value" format. The code that constructs this URL looks like this:
$fields .= "&x_login=$x_login&x_tran_key=$x_tran_key"; // etc.
[$x_login and $x_tran_key were defined previously, which is why the variable name is used instead of an actual value.]
Of course, I have to add on each student. This part, I think, is the problem. I'm using the following code:
for ($i = 0; $i < $count; $i++)
{
$j = $i + 1;
$fake = "student$j";
$fields .= "&".$_POST[$fake]."=$".$_POST[$fake];
}
Authorize.net's gateway receives this post and relays it to notify.php, which uses virtually the same code chunk to echo a list of students in an email sent to the leader:
for ($i = 0; $i < $count; $i++)
{
$j = $i + 1;
$fake = "student$j";
$message .= "$_POST[$fake]\n";
}
An actual email, copied below, demonstrates that while the variable $count (which is transmitted in the post URL) went through, the student names did not:
You have paid for the following student(s) to attend Spring College Days:
Total amount: $55.00
[As you can see, the email contains line breaks - indicating that the code chunk executed, but the student variables were not transmitted.]
Any ideas?