Home  >  Q&A  >  body text

Why do I get the "Inserted value list does not match column list: 1136 Column count does not match value count" error when the data matches?

I am getting the above error but the count of both the column and the data I am inserting is 19

try {
    $db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "INSERT INTO prescriptions (
        rxID, rxPrimeName, rxAltName, patient, prescriber, dpp, dppMetric, totalDailyDosage, 
        totalDailyPills, frequency, freqMetric, am, noon, pm, bed, prn, pharmacy, lastFill, pills
        )
    VALUES 
        (
        '$rxID', '$drugName1', '$drugName2', '$patient', '$prescriber', '$dpp', '$metric', '$totalDailyDosage,
        $totalDailyPills', '$quantity', '$frequency', '$am', '$noon', '$pm', '$bed', '$prn', '$pharmacy', '$lastFill', '$pills'
        )";
    $db->exec($sql);
    echo "New record created successfully";
} catch (PDOException $e) {
    echo $sql . "<br>" . $e->getMessage();
}
$db = null;

This is the exact error I receive:

Insert prescriptions ( rxID, rxPrimeName, rxAltName, patient, prescriber, dpp, phpcn cphpcndppMetric, totalDailyDosage, totalDailyPills, frequency, freqMetric,amnoon pm phpcnendc phpcn、bedprnpharmacylastFillpills ) Value('1111111', 'Test1', 'Test2', 'Jordan', 'Test3', '50', 'mg', '100, 2', '1', 'BID', '1', '1', '0' , '0', '0', 'KJdh', '2022-04-15', '60') SQLSTATE[21S01]: Inserted value list does not match column list: 1136 Column count does not match value count at row 1

Both sides (INSERT INTO and VALUES) have 19

When I use phpMyAdmin to insert data, the results returned are as follows:

Insert prescriptions(keyID, rxID, rxPrimeName, rxAltName, patient, prescriber, phpcnc phpcndpp, dppMetric, totalDailyDosage, totalDailyPills, frequency,freqMetricamnoonphpcnendc phpcn、pmbedprnpharmacylastFillpills) Value (NULL , '1234567', 'Test1', 'Test2', 'Jordan', 'Test3', '30', ' mg', '60', '2', '1', 'BID', '1', ' 1', '0', '0', '0', 'Atrium', '2022-04-15' , '60');

Please excuse the block on the column names above - I used backquote

around the column names

phpMyAdmin works just fineYes I know the variable data is different but all accepted types are based on columns

P粉561323975P粉561323975230 days ago366

reply all(2)I'll reply

  • P粉268284930

    P粉2682849302024-03-27 09:59:03

    The problem is that your values clause is missing quotes:

    VALUES 
    (
    '$rxID', '$drugName1', '$drugName2', '$patient', '$prescriber', '$dpp', '$metric',
    '$totalDailyDosage, <-- missing quote before comma
    -->> missing quote --> $totalDailyPills', 
    '$quantity', '$frequency', '$am', '$noon', '$pm', '$bed', '$prn', '$pharmacy', '$lastFill', '$pills'
    )";

    reply
    0
  • P粉665679053

    P粉6656790532024-03-27 00:05:56

    I counted, there are 18. Looks like you are missing ',

    at "100, 2"

    reply
    0
  • Cancelreply