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?
P粉561323975
P粉561323975 2024-03-26 12:34:51
0
2
392

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粉561323975
P粉561323975

reply all(2)
P粉268284930

The problem is that your values clause is missing quotes:

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

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

at "100, 2"
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template