Home > front end >  Data not inputting into correct database tables from form
Data not inputting into correct database tables from form

Time:10-31

The form that I am using to capture information is not inputting the data into the correct fields in the database.

I have looked at the screen for the past day and everything looks fine as far as I can tell. There are no missing variables and spellings are corerct.

The issue appears to start from med_cons / gp_surgery onwards in the database.

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

Database structure

  `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

Please can anyone help restore my sanity?

CodePudding user response:

While in your table structure the order of columns is

...
datemovedin
gp_surgery
rflfull
last_date_left
med_cons
...

you are passing your values in this order

..., $datemovedin, $med_cons, $gp_surgery, $rflfull, $last_date_left, ...

So either change the order, in which you are passing your parameters to match the order of the columns in the table.

A still better approach is, to specify the order of columns in your insert query. Because this way, you are not depending on some DB-system internals, which define the column order, but you can specify the order yourself. This is especially important, if you have queries, which don't affect all of your table's columns. So do it like the following:

INSERT INTO contacts(id, name, email, phone, ...) VALUES (?,?,?,?....)

And make sure you pass your values in $stmt->execute([$id, $name, $email, $phone, ...]) in the same order as you defined your column names in the query.

  • Related