3 回答
TA贡献1820条经验 获得超9个赞
您需要对此进行更改:
$query = "INSERT INTO ambjournal (forare, sjukskot, rakel, id, tillstand, medvet, andn, puls, blodt, triage, medvet2, andn2, puls2, blodt2, triage2, behandling, anamnes) VALUES ('$forare', '$sjukskot', '$rakel', '$id', '$tillstand', '$medvet', '$andn', '$puls', '$blodt', '$triage', '$medvet2', '$andn2', '$puls2', '$blodt2', '$triage2', '$behandling', '$anamnes');";
并将其替换为:
$query = "INSERT INTO ambjournal (forare, sjukskot, rakel, id, tillstand, medvet, andn, puls, blodt, triage, medvet2, andn2, puls2, blodt2, triage2, behandling, anamnes) VALUES (:forare, :sjukskot, :rakel, :id, :tillstand, :medvet, :andn, :puls, :blodt, :triage, :medvet2, :andn2, :puls2, :blodt2, :triage2, :behandling, :anamnes);";
更新:
你也可以这样做:
$query = "INSERT INTO ambjournal (forare, sjukskot, rakel, id, tillstand, medvet, andn, puls, blodt, triage, medvet2, andn2, puls2, blodt2, triage2, behandling, anamnes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
$stmt = $db->prepare($query);
$stmt->bindparam(1,$forare);
$stmt->bindparam(2,$sjukskot);
$stmt->bindparam(3,$rakel);
$stmt->bindparam(4,$id);
$stmt->bindparam(5,$tillstand);
$stmt->bindparam(6,$medvet);
$stmt->bindparam(7,$andn);
$stmt->bindparam(8,$puls);
$stmt->bindparam(9,$blodt);
$stmt->bindparam(10,$triage);
$stmt->bindparam(11,$medvet2);
$stmt->bindparam(12,$andn2);
$stmt->bindparam(13,$puls2);
$stmt->bindparam(14,$blodt2);
$stmt->bindparam(15,$triage2);
$stmt->bindparam(16,$behandling);
$stmt->bindparam(17,$anamnes);
$stmt->execute();
TA贡献1886条经验 获得超2个赞
在查询的第二部分,我的意思是“值”部分,您应该声明以“:”开头的参数,例如“:forare”。
您的查询应该是:
$query = "INSERT INTO ambjournal (forare, sjukskot, rakel, id, tillstand, medvet, andn, puls, blodt, triage, medvet2, andn2, puls2, blodt2, triage2, behandling, anamnes) VALUES (':forare', ':sjukskot', ':rakel', ':id', ':tillstand', ':medvet', ':andn', ':puls', ':blodt', ':triage', ':medvet2', ':andn2', ':puls2', ':blodt2', ':triage2', ':behandling', ':anamnes');";
TA贡献1851条经验 获得超4个赞
自从我使用 PDO 已经有一段时间了,但我记得我更容易将所有信息添加到一个数组中,然后通过使用相同的数组准备查询来绑定参数。你可以做这样的事情(整理 SQL 和数组以便于阅读):
$post_info = array(
'forare' => $_POST['forare'],
'sjukskot' => $_POST['sjukskot'],
'rakel' => $_POST['rakel'],
'id' => $_POST['id'],
'tillstand' => $_POST['tillstand'],
'medvet' => $_POST['medvet'],
'andn' => $_POST['andn'],
'puls' => $_POST['puls'],
'blodt' => $_POST['blodt'],
'triage' => $_POST['triage'],
'medvet2' => $_POST['medvet2'],
'andn2' => $_POST['andn2'],
'puls2' => $_POST['puls2'],
'blodt2' => $_POST['blodt2'],
'triage2' => $_POST['triage2'],
'behandling' => $_POST['behandling'],
'anamnes' => $_POST['anamnes']
);
$sql = 'INSERT INTO ambjournal
(forare,
sjukskot,
rakel,
id,
tillstand,
medvet,
andn,
puls,
blodt,
triage,
medvet2,
andn2,
puls2,
blodt2,
triage2,
behandling,
anamnes
)
VALUES
(
:forare,
:sjukskot,
:rakel,
:id,
:tillstand,
:medvet,
:andn,
:puls,
:blodt,
:triage,
:medvet2,
:andn2,
:puls2,
:blodt2,
:triage2,
:behandling,
:anamnes
)';
// Once you get this done, the next thing you do is prepare it and execute it with the array
$insert_query = $db->prepare($sql);
$insert_query->execute($post_info);
这必须有效,如果没有,您可能有一些与数据相关的问题。不正确的数据类型、数据大小或缺少信息。
- 3 回答
- 0 关注
- 80 浏览
添加回答
举报