speckytwat Posted November 10, 2017 Share Posted November 10, 2017 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; } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 10, 2017 Share Posted November 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
phpmillion Posted November 10, 2017 Share Posted November 10, 2017 He also posted question here - https://www.codingforums.com/php/388256-second-digit-integer-array-being-stripped.html At the moment, my best guess is that OP doesn't want to learn at all, and will keep posting, cross-posting and re-posting the same issue until he finds someone to rewrite and fix whole code for him. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.