简体   繁体   中英

Passing Array Value through form PHP

I have a form with the following code:

<?php    
echo '<form action="nba-agent-process-bet.php" method="post">';  
echo '<table cellpadding="0" cellspacing="0" border="1" bordercolor="#585858" width=100%>';      
echo '<tr>';  
echo '<th>Date</th>';  
echo '<th>#</th>';  
echo '<th>Team</th>';  
echo '<th>Money</th>';  
echo '<th>Spread</th>';  
echo '<th>Total</th>';  
echo '</tr>';       
for($i=0 ; $i<10;){  
$AwayTeamSpread = " ";  
$HomeTeamSpread = " ";  
foreach ($xml->Game as $Game) {   
$Date[] = $Game->Date; $AwayTeam[] = $Game->AwayTeam; $HomeTeam[] = $Game->HomeTeam; $AwayRotation[] = $Game->AwayRotation;  
$HomeRotation[] = $Game->HomeRotation; $Total[] = $Game->Total; $OverPrice[] = $Game->OverPrice;  
$UnderPrice[] = $Game->UnderPrice; $Line[] = $Game->Line; $AwayTeamPrice[] = $Game->AwayTeamPrice;  
$HomeTeamPrice[] = $Game->HomeTeamPrice; $AwayTeamMoneyLine[] = $Game->AwayTeamMoneyLine; $HomeTeamMoneyLine[] = $Game->HomeTeamMoneyLine;  
}  
foreach ($xml2->events->event as $event) {  
$Spread = $event->periods->period[0]->spread;  
$TotalPoints = $event->periods->period[0]->total;   
$AHomeRotNum = $event->participants->participant[1];   
$AVisitingRotNum = $event->participants->participant[0];  
$AHomeParticipantName = $event->participants->participant[1];  
$AVisitingParticipantName = $event->participants->participant[0];  
$MoneyLine = $event->periods->period[0]->moneyline;   
$AwayLine[] = $Spread->spread_visiting;   
$HomeLine[] = $Spread->spread_home;  
$UnderAdjust[] = $TotalPoints->under_adjust;   
$OverAdjust[] = $TotalPoints->over_adjust;  
$ATotalPoints[] = $TotalPoints->total_points;  
$VisitingRotNum[] = $AVisitingRotNum->rotnum;  
$HomeRotNum[] = $AHomeRotNum->rotnum;  
$VisitingParticipantName[] = $AVisitingParticipantName->participant_name;  
$HomeParticipantName[] = $AHomeParticipantName->participant_name;  
$AwayMoneyLine[] = $MoneyLine->moneyline_visiting;   
$HomeMoneyLine[] = $MoneyLine->moneyline_home;  
$AwaySpreadAdjust[] = $Spread->spread_adjust_visiting;   
$HomeSpreadAdjust[] = $Spread->spread_adjust_home;  
}     
echo '<tr>';  
echo "<td>$Date[$i]</td><td><table><tr><td>$VisitingRotNum[$i]</td></tr><tr><td>$HomeRotNum[$i]</td></tr></table></td><td><table><tr><td>$VisitingParticipantName[$i]</td></tr><tr><td>$HomeParticipantName[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox' name='AwayMoneyLine' value='$AwayMoneyLine[$i];$HomeParticipantName[$i]'/> $AwayMoneyLine[$i]</td></tr><tr><td><input type='checkbox' name='HomeMoneyLine' value='$HomeMoneyLine[$i];$AwayParticipantName[$i]'/>$HomeMoneyLine[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox' name='$AwaySpreadAdjust[$i]' value='$AwayLine[$i]'/> $AwayLine[$i] ($AwaySpreadAdjust[$i])</td></tr><tr><td><input type='checkbox' name='$HomeSpreadAdjust[$i]' value='$HomeLine[$i]'/> $HomeLine[$i] ($HomeSpreadAdjust[$i])</td></tr></table></td><td><table><tr><td><input type='checkbox' name='AwayTotalPoints' value='$TotalPoints[$i]'/> Over $ATotalPoints[$i]</td></tr><tr><td><input type='checkbox' name='HomeTotalPoints' value='$ATotalPoints[$i]'/> Under $ATotalPoints[$i]</td></tr></table></td>";  
echo '</tr>';  
$i++;  
}  
echo '<tr>';  
echo '<td colspan="3"><input type="submit" name="send" value="Submit"></td><td colspan="3"><input type="button" name="Clear" value="Clear" /></td>';  
echo '</tr>';  
echo ' </table>';  
?>  

Basically, the for loop runs through my xml items. The foreach loops assign values to the arrays. The arrays are printed in a table, each $i in the loop representing a row in the table. When a checkbox is selected and submitted, I would like to pass multiple arrays for the selected $i through values in the checkboxes. I have the following code in the form action:

For example, I try to pass $HomeMoneyLine and echo the value, but have had no luck. Any help would be greatly appreciated!

<?php session_start(); ?>  
<?php  
if($_POST['AwayMoneyLine'] == $_POST['$AwayMoneyLine']){  
     $bet_type="Moneyline";  
     $HomeTeam=$_POST['$HomeMoneyLine[$i]'];  
     echo $HomeTeam;  
}   
else {   
header("Location: http://www.mainurl.com/");   
}   
?>  
if($_POST['AwayMoneyLine'] == $_POST['$AwayMoneyLine']){  
                                     ^--            ^--

these are probably not the quotes you are looking for, unless you've used literal $ , A , w , etc... as the field's name in your form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM