Jump to content

Second digit in integer array being stripped


speckytwat

Recommended Posts

I have a section of script that grabs the ID of a member from a ticked checkbox, and inserts those values into a messages database table in mySQL. The weird thing is that the ID ($recipientid in the script below) has one of his digits stripped, for example I tested with IDs 17 and 23 and it inputted them in the table as 1 and 2. It works fine with single digit Recipient IDs but not with more than one digit.

I checked the data type in mySQL and it's a standard int(11).

When I echo the Recipient IDs (as below) to test, it shows them correctly. But somewhere it's stripping the second digit. Any ideas?!

    foreach ($_POST['_RecipientID'] as $key => $recipientid)
            {
                //$recipients .= $recipientid."|";
                $recipients .= "$recipientid, ";
    echo 'Recipient ID: '.$recipientid;
            //$recipientemail = $mysqli->real_escape_string($_POST['_RecipientEmail']);    
            $messagetext = $mysqli->real_escape_string($_POST['_MessageText']);    
            $sender = $mysqli->real_escape_string($_POST['_Sender']);    
            $dateadded = date('Y-m-d H:i:s');
                for ($i=0; $i<count($recipientid); $i++)
        $addmessagetotable = $mysqli->query("INSERT INTO messages (RecipientID, MessageText, Sender, DateSent) VALUES ('".$recipientid[$i]."','$messagetext','$sender','$dateadded')");
                var_dump();
                //echo 'Email is '.$recipientemail;
            }
Link to comment
Share on other sites

in your Oct 12th thread for this same code/problem - https://forums.phpfreaks.com/topic/305346-issue-inserting-checkbox-values-into-mysql-from-php/ you were given a reply that would have used the correct value.

 

you are already looping over the submitted array in the foreach(){} loop. the for(){} loop you have now added to the code is nonsense. it's looping over the digits of the integer and only getting the first one because the count() function is returning a 1.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.