I have an Inbox that has a check-box next to each Message.
The User can check any combination of Messages, and then choose from the following items in a Select List and click “Go”…
[INDENT]- Mark as Read
- Mark as Unread
- Mark as Flagged
- Mark as Not Flagged
- Delete[/INDENT]
My current problem occurs when no check-boxes are selected and I choose “Mark as Read” and “Go”.
I get this error…
Array ( [pmAction] => Mark as Read [cmdGo] => Go ) 1
( ! ) Notice: Undefined variable: msgArray in /Users/user1/Documents/DEV/++htdocs/06_Debbie/account/inbox.php on line 68
Call Stack
# Time Memory Function Location
1 0.0009 100316 {main}( ) ../inbox.php:0
( ! ) Warning: Invalid argument supplied for foreach() in /Users/user1/Documents/DEV/++htdocs/06_Debbie/account/inbox.php on line 68
Call Stack
# Time Memory Function Location
1 0.0009 100316 {main}( ) ../inbox.php:0
Here is a snippet of my PHP… (Lines 47-77)
// *************************************************************
// HANDLE FORM. *
// *************************************************************
if ($_SERVER['REQUEST_METHOD']=='POST'){
// Form was Submitted (Post).
// Initialize Errors Array.
// $errors = array();
echo print_r($_POST);
//exit();
// ************************
// Check Message Action. *
// ************************
if ($_POST['pmAction']=="Mark as Read"){
// ************************
// Mark Message as Read. *
// ************************
foreach($msgArray as $msgID => $msgValue){
// echo "<p>\\$msg[$msgID] = $msgValue</p>";
// Build query.
$q1 = "UPDATE pm_recipient
SET read_on=NOW(),
updated_on=NOW()
WHERE member_id_to=?
AND message_id=?
LIMIT 1";
And this is a snippet of my dynamically created Form…
<?php
// ************************
// Create 'Inbox' Output. *
// ************************
// Display message.
if (!$messagesFound){
echo "<p>There are no messages in your Inbox.</p>";
}
// Loop through Messages.
while (mysqli_stmt_fetch($stmt6)){
echo "<tr" . (is_null($readOn) ? " class='pmRead'" : "") . ">
<td class='colSelect'>
<input id='" . $pmID . "' name=msg[" . $pmID . "] type='checkbox' value='TRUE' />
</td>
<td class='colFlag'>"
. (($flag==TRUE) ? '<img src="/images/Flag_Red_20x22.png" width="15" alt="" />' : '•') .
"</td>
<td>$fromUsername</td>
<td><a class='msgLink' href='/account/view_pm.php?msg=" . $pmID . "'>$subject</a></td>
<td>$sentOn</td>
</tr>";
}
?>
How can I fix this so if the User forgets to check at least one message my code doesn’t blow up?! :-/
Thanks,
Debbie