来自PHP的MySQL INSERT INTO:// INPUT多行

I have data (exact) from this HTTP POST:

rowno=1.00000000&date_line=2014-10-07&name=Dan%20Volunteer&affiliation=Enterprise&checkno=1701&amount=20025.00000000&total=20250.00000000&notes=&date_deposit=&rowno=2.00000000&date_line=2014-10-07&name=Harper%20Lee&affiliation=Enterprise%20B&checkno=1702&amount=225

then this code to process

<?php

file_get_contents("php://input");

$db = null;
if (isset($_SERVER['SERVER_SOFTWARE']) &&
strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
  // Connect from App Engine.
  try{
     $db = new pdo('mysql:unix_socket=/cloudsql/wonder:bread;dbname=loaf', 'root', '');
  }catch(PDOException $ex){
      die(json_encode(
          array('outcome' => false, 'message' => 'Unable to connect.')
          )
      );
  }
};

try {
  if (array_key_exists('name', $_POST)) {
    $stmt = $db->prepare('INSERT INTO entries (name, affiliation) VALUES (:name, :affiliation)');
    $stmt->execute(array(':name' => htmlspecialchars($_POST['name']), ':affiliation' => htmlspecialchars($_POST['affiliation'])));
    $affected_rows = $stmt->rowCount();
    // Log $affected_rows.
  }
} catch (PDOException $ex) {
  // Log error.
}
$db = null;
?>
<?php

header("Content-type: application/vnd.fdf");
// read and store the data however you want
// reply with some FDF data
echo <<<RESPONSE
%FDF-1.2
1 0 obj
<< /FDF <<
/Status (Wham bam! File sent.)
>>
>>
endobj
trailer
<< /Root 1 0 R >>
%%EOF
RESPONSE;
?>

This http post has two records (row/recount count always varies), but only data from the last row is being inserted. Need all rows.

I'm going to stab at this one....I think what is happening is that you are just processing the return post as is, so the first rowno is being skipped over (rather the second rowno is overwriting the first). If you receive that post back as a string, you need to split it by preg_match() or explode() so that you can loop over it with your try.

Try this class on your string. This class will split the string into arrays based on rows. Then you need to take the resulting array $insert then process each array in your an sql loop...does that make sense?

class ProcessPost
        {
            public  static  function Split($value = '',$splitVal = 'rowno=')
                {
                    if(!empty($value)) {
                            // Explode by row values
                            $rows   =   explode($splitVal,$value);
                            $rows   =   array_filter($rows);

                            if(is_array($rows) && !empty($rows)) {
                                    foreach($rows as  $_row => $querystring) {
                                            parse_str($splitVal.$querystring,$_array[]);
                                        }

                                    foreach($_array as $row_key => $row_val) {
                                            if(empty($row_val))
                                                unset($_array[$row_key]);
                                        }

                                    return $_array;
                                }
                        }
                }
        }

    $test   =   'rowno=1.00000000&date_line=2014-10-07&name=Dan%20Volunteer&affiliation=Enterprise&checkno=1701&amount=20025.00000000&total=20250.00000000&notes=&date_deposit=&rowno=2.00000000&date_line=2014-10-07&name=Harper%20Lee&affiliation=Enterprise%20B&checkno=1702&amount=225';

    $insert =   ProcessPost::Split($test);