I need some help learning how to pass Arrays and Variables when my Form is submitted.
Initially when my Script/Form loads, I build two arrays like this…
//NEW
// Set Incoming Array Counter.
$i = 1;
// Fetch record.
while (mysqli_stmt_fetch($stmt6)){
// Build All Incoming Array.
$allIncomingArray[$i] = $pmID;
echo $allIncomingArray[$i] . '<br />';
// Build Incoming Array.
$incomingArray[$i] = array('pmID' => $pmID,
'readOn' => $readOn,
'flag' => $flag,
'fromID' => $fromID,
'fromUsername' => $fromUsername,
'subject' => $subject,
'sentOn' => $sentOn);
$i = $i + 1;
}//End of BUILD INCOMING ARRAY
(As you can see, I echoed the 1st array to the screen to confirm that it exists and has values.)
At the bottom of my script, I have my PHP/HTML which builds the Form like this…
// ****************************
// Create 'Incoming' Output. *
// ****************************
echo "<h2>Incoming Messages</h2>
<table border='1' cellspacing='1'>
<thead>
<!-- Header Bar -->
<tr>
<td id='headerBar' colspan='5'>
<!-- Message Actions -->
<select name='pmAction'>
<option value=''>For the selected...</option>
<option value='In_Unread'>Mark as Unread</option>
<option value='In_Read'>Mark as Read</option>
</select>
<!-- Submit Button -->
<input type='submit' name='submit' value='Go'/>
</td>
</tr>
<!-- LOOK HERE -->
<!-- Column Headings -->
<tr>
<th class='colSelect' />
<input name='allIncomingArray[]' type='checkbox' value='TRUE' />
</th>
<th id='colFlag'>
<img src='/images/Flag_Red_20x22.png' width='15' alt='' />
</th>
<th id='colFrom'>From</th>
<th id='colSubject'>Subject</th>
<th id='colDate'>Date</th>
</tr>
</thead>
(As you can see in this snippet, I am trying to pass the $allIncomingArray in the <input name=‘allIncomingArray[]’ line…)
And at the top of my script I have this code to handle the Form when it is submitted…
// ****************************************************
// HANDLE FORM. *
// ****************************************************
if ($_SERVER['REQUEST_METHOD']=='POST'){
// Form was Submitted (Post).
// ****************************
// Check for Message Action. *
// ****************************
if ($_POST['pmAction']=="In_Unread"){
// **************************
// Mark Incoming as Unread. *
// **************************
echo var_dump($_POST['allIncomingArray']);
foreach($allIncomingArray as $allKey => $allValue){
echo '$allKey = ' . $allKey . ', $allValue = ' . $allValue . '<br />';
}
Here is the problem…
If I choose “Mark as Read” in my drop-down, and I check the Top Check-box in the “Select” column, and then I choose “Go”, I was expecting that my $allIncomingArray to get passed from my script in the $_POST array and end up being echoed to the screen as confirmation.
But instead, I get this…
array
0 => string ‘TRUE’ (length=4)
And if I just choose “Mark as Read” from my drop-down, but I do NOT check the Top Check-box, then I get this error…
Notice: Undefined index: allIncomingArray in /Users/user1/Documents/DEV/++htdocs/06_Debbie/account/messages.php on line 94
Call Stack
# Time Memory Function Location
1 0.0021 205724 {main}( ) ../messages.php:0
null
Can someone help me figure this out?! :-/
Thanks,
Debbie