列已创建,但未发布任何值

我遇到了这个问题,我的表单只发布了没有任何值的列本身。我试图找出问题所在,但没有任何运气。我的想法是变量有问题,但真的不知道出了什么问题。


编辑:我已经解决了这个问题,它不是 PDO/php。只是 html 表单的结构错误,现在已修复多个表单。感谢所有的帮助!


<?php

include ('../functions.php');

$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'];


require_once('../configs/dbconfigpdo.php');


try{


$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');";


$stmt = $db->prepare($query);

$stmt->bindparam(":forare",$forare);

$stmt->bindparam(":sjukskot",$sjukskot);

$stmt->bindparam(":rakel",$rakel);

$stmt->bindparam(":id",$id);

$stmt->bindparam(":tillstand",$tillstand);

$stmt->bindparam(":medvet",$medvet);

$stmt->bindparam(":andn",$andn);

$stmt->bindparam(":puls",$puls);

$stmt->bindparam(":blodt",$blodt);

$stmt->bindparam(":triage",$triage);

$stmt->bindparam(":medvet2",$medvet2);

$stmt->bindparam(":andn2",$andn2);

$stmt->bindparam(":puls2",$puls2);

$stmt->bindparam(":blodt2",$blodt2);

$stmt->bindparam(":triage2",$triage2);

$stmt->bindparam(":behandling",$behandling);

$stmt->bindparam(":anamnes",$anamnes);

$stmt->execute();


header ('Location: ../ambulansjournal.php');

exit();

}


catch(PDOException $exception){


die('ERROR: ' . $exception->getMessage());


}

?>


牛魔王的故事
浏览 81回答 3
3回答

慕妹3146593

您需要对此进行更改:$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();

MM们

在查询的第二部分,我的意思是“值”部分,您应该声明以“:”开头的参数,例如“:forare”。您的查询应该是:$query&nbsp;=&nbsp;"INSERT&nbsp;INTO&nbsp;ambjournal&nbsp;(forare,&nbsp;sjukskot,&nbsp;rakel,&nbsp;id,&nbsp;tillstand,&nbsp;medvet,&nbsp;andn,&nbsp;puls,&nbsp;blodt,&nbsp;triage,&nbsp;medvet2,&nbsp;andn2,&nbsp;puls2,&nbsp;blodt2,&nbsp;triage2,&nbsp;behandling,&nbsp;anamnes)&nbsp;VALUES&nbsp;(':forare',&nbsp;':sjukskot',&nbsp;':rakel',&nbsp;':id',&nbsp;':tillstand',&nbsp;':medvet',&nbsp;':andn',&nbsp;':puls',&nbsp;':blodt',&nbsp;':triage',&nbsp;':medvet2',&nbsp;':andn2',&nbsp;':puls2',&nbsp;':blodt2',&nbsp;':triage2',&nbsp;':behandling',&nbsp;':anamnes');";

繁花不似锦

自从我使用 PDO 已经有一段时间了,但我记得我更容易将所有信息添加到一个数组中,然后通过使用相同的数组准备查询来绑定参数。你可以做这样的事情(整理 SQL 和数组以便于阅读):$post_info = array(&nbsp; &nbsp; 'forare' => $_POST['forare'],&nbsp; &nbsp; 'sjukskot' => $_POST['sjukskot'],&nbsp; &nbsp; 'rakel' => $_POST['rakel'],&nbsp; &nbsp; 'id' => $_POST['id'],&nbsp; &nbsp; 'tillstand' => $_POST['tillstand'],&nbsp; &nbsp; 'medvet' => $_POST['medvet'],&nbsp; &nbsp; 'andn' => $_POST['andn'],&nbsp; &nbsp; 'puls' => $_POST['puls'],&nbsp; &nbsp; 'blodt' => $_POST['blodt'],&nbsp; &nbsp; 'triage' => $_POST['triage'],&nbsp; &nbsp; 'medvet2' => $_POST['medvet2'],&nbsp; &nbsp; 'andn2' => $_POST['andn2'],&nbsp; &nbsp; 'puls2' => $_POST['puls2'],&nbsp; &nbsp; 'blodt2' => $_POST['blodt2'],&nbsp; &nbsp; 'triage2' => $_POST['triage2'],&nbsp; &nbsp; 'behandling' => $_POST['behandling'],&nbsp; &nbsp; 'anamnes' => $_POST['anamnes']);$sql = 'INSERT INTO ambjournal&nbsp; &nbsp; (forare,&nbsp; &nbsp; sjukskot,&nbsp; &nbsp; rakel,&nbsp; &nbsp; id,&nbsp; &nbsp; tillstand,&nbsp; &nbsp; medvet,&nbsp; &nbsp; andn,&nbsp; &nbsp; puls,&nbsp; &nbsp; blodt,&nbsp; &nbsp; triage,&nbsp; &nbsp; medvet2,&nbsp; &nbsp; andn2,&nbsp; &nbsp; puls2,&nbsp; &nbsp; blodt2,&nbsp; &nbsp; triage2,&nbsp; &nbsp; behandling,&nbsp; &nbsp; anamnes)VALUES(&nbsp; &nbsp; :forare,&nbsp;&nbsp; &nbsp; :sjukskot,&nbsp; &nbsp; :rakel,&nbsp; &nbsp; :id,&nbsp; &nbsp; :tillstand,&nbsp;&nbsp; &nbsp; :medvet,&nbsp;&nbsp; &nbsp; :andn,&nbsp;&nbsp; &nbsp; :puls,&nbsp; &nbsp; :blodt,&nbsp; &nbsp; :triage,&nbsp; &nbsp; :medvet2,&nbsp; &nbsp; :andn2,&nbsp;&nbsp; &nbsp; :puls2,&nbsp;&nbsp; &nbsp; :blodt2,&nbsp;&nbsp; &nbsp; :triage2,&nbsp;&nbsp; &nbsp; :behandling,&nbsp; &nbsp; :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);这必须有效,如果没有,您可能有一些与数据相关的问题。不正确的数据类型、数据大小或缺少信息。
打开App,查看更多内容
随时随地看视频慕课网APP