我用來捕獲資訊的表單沒有將資料輸入到資料庫中的正確欄位中。
過去一天我一直看著螢屏,據我所知,一切看起來都很好。沒有遺漏變數,拼寫正確。
該問題似乎從資料庫中的 med_cons / gp_surgery 開始。
$id = isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != 'auto' ? $_POST['id'] : NULL;
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$title = 'Client';
$created = isset($_POST['created']) ? $_POST['created'] : '';
$status = isset($_POST['status']) ? $_POST['status'] : '';
$riskdv = isset($_POST['riskdv']) ? $_POST['riskdv'] : '';
$nin = isset($_POST['nin']) ? $_POST['nin'] : '';
$dob = isset($_POST['dob']) ? $_POST['dob'] : '';
$nextofkin = isset($_POST['nextofkin']) ? $_POST['nextofkin'] : '';
$address = isset($_POST['address']) ? $_POST['address'] : '';
$refname = isset($_POST['refname']) ? $_POST['refname'] : '';
$refagency = isset($_POST['refagency']) ? $_POST['refagency'] : '';
$refadd = isset($_POST['refadd']) ? $_POST['refadd'] : '';
$refemail = isset($_POST['refemail']) ? $_POST['refemail'] : '';
$refnum = isset($_POST['refnum']) ? $_POST['refnum'] : '';
$riskvoi = isset($_POST['riskvoi']) ? $_POST['riskvoi'] : '';
$riskar = isset($_POST['riskar']) ? $_POST['riskar'] : '';
$risksat = isset($_POST['risksat']) ? $_POST['risksat'] : '';
$riskpph = isset($_POST['riskpph']) ? $_POST['riskpph'] : '';
$riskpmh = isset($_POST['riskpmh']) ? $_POST['riskpmh'] : '';
$refpos = isset($_POST['refpos']) ? $_POST['refpos'] : '';
$mentalhealth = isset($_POST['mentalhealth']) ? $_POST['mentalhealth'] : '';
$hisdrug = isset($_POST['hisdrug']) ? $_POST['hisdrug'] : '';
$exoff = isset($_POST['exoff']) ? $_POST['exoff'] : '';
$learndif = isset($_POST['learndif']) ? $_POST['learndif'] : '';
$hisalc = isset($_POST['hisalc']) ? $_POST['hisalc'] : '';
$fled = isset($_POST['fled']) ? $_POST['fled'] : '';
$rousl = isset($_POST['rousl']) ? $_POST['rousl'] : '';
$trave = isset($_POST['trave']) ? $_POST['trave'] : '';
$yplc = isset($_POST['yplc']) ? $_POST['yplc'] : '';
$psd = isset($_POST['psd']) ? $_POST['psd'] : '';
$hivaids = isset($_POST['hivaids']) ? $_POST['hivaids'] : '';
$hep = isset($_POST['hep']) ? $_POST['hep'] : '';
$phyneeds = isset($_POST['phyneeds']) ? $_POST['phyneeds'] : '';
$mentneeds = isset($_POST['mentneeds']) ? $_POST['mentneeds'] : '';
$meds = isset($_POST['meds']) ? $_POST['meds'] : '';
$subdose = isset($_POST['subdose']) ? $_POST['subdose'] : '';
$methmil = isset($_POST['methmil']) ? $_POST['methmil'] : '';
$alcdepend = isset($_POST['alcdepend']) ? $_POST['alcdepend'] : '';
$ivdrug = isset($_POST['ivdrug']) ? $_POST['ivdrug'] : '';
$onmeth = isset($_POST['onmeth']) ? $_POST['onmeth'] : '';
$compdetox = isset($_POST['compdetox']) ? $_POST['compdetox'] : '';
$drugdepend = isset($_POST['drugdepend']) ? $_POST['drugdepend'] : '';
$dip = isset($_POST['dip']) ? $_POST['dip'] : '';
$attcdp = isset($_POST['attcdp']) ? $_POST['attcdp'] : '';
$heroin = isset($_POST['heroin']) ? $_POST['heroin'] : '';
$canna = isset($_POST['canna']) ? $_POST['canna'] : '';
$meth = isset($_POST['meth']) ? $_POST['meth'] : '';
$coc = isset($_POST['coc']) ? $_POST['coc'] : '';
$crack = isset($_POST['crack']) ? $_POST['crack'] : '';
$solvents = isset($_POST['solvents']) ? $_POST['solvents'] : '';
$amph = isset($_POST['amph']) ? $_POST['amph'] : '';
$spice = isset($_POST['spice']) ? $_POST['spice'] : '';
$premed = isset($_POST['premed']) ? $_POST['premed'] : '';
$halluc = isset($_POST['halluc']) ? $_POST['halluc'] : '';
$subu = isset($_POST['subu']) ? $_POST['subu'] : '';
$alclevel = isset($_POST['alclevel']) ? $_POST['alclevel'] : '';
$otherinfo = isset($_POST['otherinfo']) ? $_POST['otherinfo'] : '';
$btype = isset($_POST['btype']) ? $_POST['btype'] : '';
$bamount = isset($_POST['bamount']) ? $_POST['bamount'] : '';
$bstartdate = isset($_POST['bstartdate']) ? $_POST['bstartdate'] : '';
$bnextpay = isset($_POST['bnextpay']) ? $_POST['bnextpay'] : '';
$padd1 = isset($_POST['padd1']) ? $_POST['padd1'] : '';
$padd2 = isset($_POST['padd2']) ? $_POST['padd2'] : '';
$preoff = isset($_POST['preoff']) ? $_POST['preoff'] : '';
$pendcase = isset($_POST['pendcase']) ? $_POST['pendcase'] : '';
$precon = isset($_POST['precon']) ? $_POST['precon'] : '';
$onprob = isset($_POST['onprob']) ? $_POST['onprob'] : '';
$shop = isset($_POST['shop']) ? $_POST['shop'] : '';
$cook = isset($_POST['cook']) ? $_POST['cook'] : '';
$money = isset($_POST['money']) ? $_POST['money'] : '';
$cleaning = isset($_POST['cleaning']) ? $_POST['cleaning'] : '';
$perh = isset($_POST['perh']) ? $_POST['perh'] : '';
$housing_benefit_claim_date = isset($_POST['housing_benefit_claim_date']) ? $_POST['housing_benefit_claim_date'] : '';
$housing_benefit_reference = isset($_POST['housing_benefit_reference']) ? $_POST['housing_benefit_reference'] : '';
$housing_benefit_cancelled = isset($_POST['housing_benefit_cancelled']) ? $_POST['housing_benefit_cancelled'] : 'No';
$date_left_left = isset($_POST['date_left_left']) ? $_POST['date_left_left'] : '';
$number_of_times_at_reflections = isset($_POST['number_of_times_at_reflections']) ? $_POST['number_of_times_at_reflections'] : '';
$amount_of_service_charge_owed = isset($_POST['amount_of_service_charge_owed']) ? $_POST['amount_of_service_charge_owed'] : '';
$reason_for_leaving = isset($_POST['reason_for_leaving']) ? $_POST['reason_for_leaving'] : '';
$home_town = isset($_POST['home_town']) ? $_POST['home_town'] : '';
$town_moved_to = isset($_POST['town_moved_to']) ? $_POST['town_moved_to'] : '';
$med_cons = isset($_POST['med_cons']) ? $_POST['med_cons'] : '';
$gp_surgery = isset($_POST['gp_surgery']) ? $_POST['gp_surgery'] : '';
$last_date_left = isset($_POST['last_date_left']) ? $_POST['last_date_left'] : '';
$rflfull = isset($_POST['rflfull']) ? $_POST['rflfull'] : '';
$datemovedin = isset($_POST['datemovedin']) ? $_POST['datemovedin'] : '';
$addinfo = isset($_POST['addinfo']) ? $_POST['addinfo'] : '';
$compldetox = isset($_POST['compldetox']) ? $_POST['compldetox'] : 'false';
$complprog = isset($_POST['complprog']) ? $_POST['complprog'] : 'false';
$dietaryreq = isset($_POST['dietaryreq']) ? $_POST['dietaryreq'] : '';
$image = $imageSource;
$is_moved_in = '0';
$stmt = $pdo->prepare('INSERT INTO contacts VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )');
$result = $stmt->execute([$id, $name, $email, $phone, $title, $created, $status, $riskdv, $nin, $dob, $nextofkin, $address, $refname, $refagency, $refadd, $refemail, $refnum, $riskvoi, $riskar, $risksat, $riskpph, $riskpmh, $refpos, $mentalhealth, $hisdrug, $exoff, $learndif, $hisalc, $fled, $rousl, $trave, $yplc, $psd, $hivaids, $hep, $phyneeds, $mentneeds, $meds, $subdose, $methmil, $alcdepend, $ivdrug, $onmeth, $compdetox, $drugdepend, $dip, $attcdp, $heroin, $canna, $meth, $coc, $crack, $solvents, $amph, $spice, $premed, $halluc, $subu, $alclevel, $otherinfo, $btype, $bamount, $bstartdate, $bnextpay, $padd1, $padd2, $preoff, $pendcase, $precon, $onprob, $shop, $cook, $money, $cleaning, $perh, $housing_benefit_claim_date, $housing_benefit_reference, $housing_benefit_cancelled, $date_left_left, $number_of_times_at_reflections, $amount_of_service_charge_owed, $reason_for_leaving, $home_town, $town_moved_to, $image, $is_moved_in, $datemovedin, $med_cons, $gp_surgery, $rflfull, $last_date_left, $addinfo, $compldetox, $complprog, $dietaryreq]);
資料庫結構
`id` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP,
`status` varchar(50) DEFAULT NULL,
`riskdv` text,
`nin` varchar(50) DEFAULT NULL,
`dob` date DEFAULT NULL,
`nextofkin` varchar(255) DEFAULT NULL,
`address` text,
`refname` varchar(255) DEFAULT NULL,
`refagency` varchar(255) DEFAULT NULL,
`refadd` text,
`refemail` varchar(255) DEFAULT NULL,
`refnum` varchar(255) DEFAULT NULL,
`riskvoi` text,
`riskar` text,
`risksat` text,
`riskpph` text,
`riskpmh` text,
`refpos` varchar(50) DEFAULT NULL,
`mentalhealth` varchar(255) DEFAULT NULL,
`hisdrug` varchar(255) DEFAULT NULL,
`exoff` varchar(255) DEFAULT NULL,
`learndif` varchar(255) DEFAULT NULL,
`hisalc` varchar(255) DEFAULT NULL,
`fled` varchar(255) DEFAULT NULL,
`rousl` varchar(255) DEFAULT NULL,
`trave` varchar(255) DEFAULT NULL,
`yplc` varchar(255) DEFAULT NULL,
`psd` varchar(255) DEFAULT NULL,
`hivaids` varchar(255) DEFAULT NULL,
`hep` varchar(255) DEFAULT NULL,
`phyneeds` text,
`mentneeds` text,
`meds` text,
`subdose` varchar(255) DEFAULT NULL,
`methmil` varchar(255) DEFAULT NULL,
`alcdepend` varchar(255) DEFAULT NULL,
`ivdrug` varchar(255) DEFAULT NULL,
`onmeth` varchar(255) DEFAULT NULL,
`compdetox` varchar(255) DEFAULT NULL,
`drugdepend` varchar(255) DEFAULT NULL,
`dip` varchar(255) DEFAULT NULL,
`attcdp` varchar(255) DEFAULT NULL,
`heroin` varchar(255) DEFAULT NULL,
`canna` varchar(255) DEFAULT NULL,
`meth` varchar(255) DEFAULT NULL,
`coc` varchar(255) DEFAULT NULL,
`crack` varchar(255) DEFAULT NULL,
`solvents` varchar(255) DEFAULT NULL,
`amph` varchar(255) DEFAULT NULL,
`spice` varchar(255) DEFAULT NULL,
`premed` varchar(255) DEFAULT NULL,
`halluc` varchar(255) DEFAULT NULL,
`subu` varchar(255) DEFAULT NULL,
`alclevel` varchar(255) DEFAULT NULL,
`otherinfo` text,
`btype` varchar(255) DEFAULT NULL,
`bamount` varchar(255) DEFAULT NULL,
`bstartdate` varchar(255) DEFAULT NULL,
`bnextpay` varchar(255) DEFAULT NULL,
`padd1` text,
`padd2` text,
`preoff` text,
`pendcase` text,
`precon` text,
`onprob` text,
`shop` varchar(255) DEFAULT NULL,
`cook` varchar(255) DEFAULT NULL,
`money` varchar(255) DEFAULT NULL,
`cleaning` varchar(255) DEFAULT NULL,
`perh` varchar(255) DEFAULT NULL,
`housing_benefit_claim_date` date DEFAULT NULL,
`housing_benefit_reference` varchar(225) DEFAULT NULL,
`housing_benefit_cancelled` varchar(20) DEFAULT NULL,
`date_left_left` date DEFAULT NULL,
`number_of_times_at_reflections` int(100) DEFAULT NULL,
`amount_of_service_charge_owed` varchar(50) DEFAULT NULL,
`reason_for_leaving` varchar(50) DEFAULT NULL,
`home_town` varchar(100) DEFAULT NULL,
`town_moved_to` varchar(100) DEFAULT NULL,
`image` varchar(225) DEFAULT NULL,
`is_moved_in` tinyint(4) DEFAULT '0',
`datemovedin` date DEFAULT NULL,
`gp_surgery` varchar(20) DEFAULT NULL,
`rflfull` varchar(200) DEFAULT NULL,
`last_date_left` varchar(200) DEFAULT NULL,
`med_cons` varchar(255) DEFAULT NULL,
`addinfo` varchar(2000) NOT NULL,
`compldetox` varchar(255) DEFAULT NULL,
`complprog` varchar(255) DEFAULT NULL,
`dietaryreq` varchar(999) DEFAULT NULL
請問有人能幫我恢復理智嗎?
uj5u.com熱心網友回復:
在您的表結構中,列的順序是
...
datemovedin
gp_surgery
rflfull
last_date_left
med_cons
...
您正在按此順序傳遞您的值
..., $datemovedin, $med_cons, $gp_surgery, $rflfull, $last_date_left, ...
因此,要么更改傳遞引數的順序,以匹配表中列的順序。
更好的方法是在插入查詢中指定列的順序。因為通過這種方式,您不依賴于定義列順序的某些 DB 系統內部結構,但您可以自己指定順序。如果您有不影響表的所有列的查詢,這一點尤其重要。因此,請執行以下操作:
INSERT INTO contacts(id, name, email, phone, ...) VALUES (?,?,?,?....)
并確保$stmt->execute([$id, $name, $email, $phone, ...])以與在查詢中定義列名的順序相同的順序傳遞值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/342396.html
