为什么我在数据匹配时收到 "Insert value list does not match column list: 1136 Column count doesn't match value count" 错误?
Why am I getting a "Insert value list does not match column list: 1136 Column count doesn't match value count" error when the data matches?
我收到上述错误,但我对要插入的列和数据的计数都是 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;
这是我收到的确切错误:
INSERT INTO prescriptions
( rxID
, rxPrimeName
, rxAltName
, patient
, prescriber
, dpp
, dppMetric
, totalDailyDosage
, totalDailyPills
, frequency
, freqMetric
, am
, noon
, pm
, bed
, prn
, pharmacy
, lastFill
, pills
) VALUES ( '1111111', 'Test1', 'Test2', 'Jordan', 'Test3', '50', 'mg', '100, 2', '1', 'BID', '1', '1', '0', '0', '0', 'KJdh', '2022-04-15', '60' )
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1
双方(INSERT INTO
和VALUES
)有19
当我使用 phpMyAdmin 插入数据时,返回的内容如下:
INSERT INTO prescriptions
(keyID
, rxID
, rxPrimeName
, rxAltName
, patient
, prescriber
, dpp
, dppMetric
, totalDailyDosage
, totalDailyPills
, frequency
, freqMetric
, am
, noon
, pm
, bed
, prn
, pharmacy
, lastFill
, pills
) VALUES (NULL, '1234567', 'Test1', 'Test2', 'Jordan', 'Test3', '30', 'mg', '60', '2', '1', 'BID', '1', '1', '0', '0', '0', 'Atrium', '2022-04-15', '60');
请原谅上面列名上的块 - 我在列名周围使用 backquote
phpMyAdmin 完美运行是的,我知道变量数据不同,但基于列的所有可接受类型
我数到18个。
看起来你在 '100, 2',
处遗漏了 '
问题是您的 values
子句缺少引号:
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'
)";
我收到上述错误,但我对要插入的列和数据的计数都是 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;
这是我收到的确切错误:
INSERT INTO
prescriptions
(rxID
,rxPrimeName
,rxAltName
,patient
,prescriber
,dpp
,dppMetric
,totalDailyDosage
,totalDailyPills
,frequency
,freqMetric
,am
,noon
,pm
,bed
,prn
,pharmacy
,lastFill
,pills
) VALUES ( '1111111', 'Test1', 'Test2', 'Jordan', 'Test3', '50', 'mg', '100, 2', '1', 'BID', '1', '1', '0', '0', '0', 'KJdh', '2022-04-15', '60' ) SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1
双方(INSERT INTO
和VALUES
)有19
当我使用 phpMyAdmin 插入数据时,返回的内容如下:
INSERT INTO
prescriptions
(keyID
,rxID
,rxPrimeName
,rxAltName
,patient
,prescriber
,dpp
,dppMetric
,totalDailyDosage
,totalDailyPills
,frequency
,freqMetric
,am
,noon
,pm
,bed
,prn
,pharmacy
,lastFill
,pills
) VALUES (NULL, '1234567', 'Test1', 'Test2', 'Jordan', 'Test3', '30', 'mg', '60', '2', '1', 'BID', '1', '1', '0', '0', '0', 'Atrium', '2022-04-15', '60');
请原谅上面列名上的块 - 我在列名周围使用 backquote
phpMyAdmin 完美运行是的,我知道变量数据不同,但基于列的所有可接受类型
我数到18个。 看起来你在 '100, 2',
处遗漏了 '问题是您的 values
子句缺少引号:
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'
)";