0

Searched SO first, I can't find an answer that is fit for my problem. Found some fixes but it doesn't do the trick. I'm trying to insert 40 variables into a row. The execute() function returns

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

I have even used a "Text difference checker" to check whether the params in the VALUES and my bindparam() do not have any typos in it and nothing came out.

 $stmt = $conn->prepare("INSERT INTO `wp_coachview_selecterenOpleiding` 
VALUES (:OpleidingId,:OpleidingsSoortId,:BeginDatumInteger,
        :BeginDatum,:BeginDatumString,:EindDatumInteger,
        :EindDatumString,:EindDatum,:BeginEindDatum,
        :OpleidingsSoortNaam,:OpleidingsSoortCode,:OpleidingsSoort,
        :Code,:Naam,:Opleiding,
        :AantalBezet,:AantalVrij,:IsAantalVrijNull,
        :MinCursisten,:IsMinCursistenNull,:MaxCursisten,
        :IsMaxCursistenNull,:Opmerking,:ContactPersonId,
        :ContactPersonNaam,:ContactPerson2Id,:ContactPerson2Naam,
        :OpleidingStatusId,:OpleidingStatusNaam,:PublicatieWebsite,
        :PublicatiePlanning,:Planningstype,:PlanningsfrequentieAantal,
        :PlanningsfrequentieTijdseenheid,:PlanningWeekdagen,:PlanningConflictafhandeling,
        :TotAantalUur,:TotStudieBelasting,:TotAantalOnderdelen)");

 $stmt->bindParam(':OpleidingId',           ($opleiding['OpleidingId']) ? $opleiding['OpleidingId'] : 'NULL');
 $stmt->bindParam(':OpleidingsSoortId',     ($opleiding['OpleidingsSoortId']) ? $opleiding['OpleidingsSoortId'] : 'NULL');
 $stmt->bindParam(':BeginDatumInteger',     ($opleiding['BeginDatumInteger']) ? $opleiding['BeginDatumInteger'] : 'NULL' );
 $stmt->bindParam(':BeginDatum',            ($opleiding['BeginDatum']) ? $opleiding['BeginDatum'] : 'NULL' );
 $stmt->bindParam(':BeginDatumString',      ($opleiding['BeginDatumString']) ? $opleiding['BeginDatumString'] : 'NULL' );
 $stmt->bindParam(':EindDatumInteger ',     ($opleiding['EindDatumInteger']) ? $opleiding['EindDatumInteger'] : 'NULL' );
 $stmt->bindParam(':EindDatumString',       ($opleiding['EindDatumString']) ? $opleiding['EindDatumString'] : 'NULL' );
 $stmt->bindParam(':EindDatum',             ($opleiding['EindDatum']) ? $opleiding['EindDatum'] : 'NULL' );
 $stmt->bindParam(':BeginEindDatum',        ($opleiding['BeginEindDatum']) ? $opleiding['BeginEindDatum'] : 'NULL' );
 $stmt->bindParam(':OpleidingsSoortNaam',   ($opleiding['OpleidingsSoortNaam']) ? $opleiding['OpleidingsSoortNaam'] : 'NULL' );
 $stmt->bindParam(':OpleidingsSoortCode',   ($opleiding['OpleidingsSoortCode']) ? $opleiding['OpleidingsSoortCode'] : 'NULL' );
 $stmt->bindParam(':OpleidingsSoort',       ($opleiding['OpleidingsSoort']) ? $opleiding['OpleidingsSoort'] : 'NULL' );
 $stmt->bindParam(':Code',                  ($opleiding['Code']) ? $opleiding['Code'] : 'NULL' );
 $stmt->bindParam(':Naam',                  ($opleiding['Naam']) ? $opleiding['Naam'] : 'NULL' );
 $stmt->bindParam(':Opleiding',             ($opleiding['Opleiding']) ? $opleiding['Opleiding'] : 'NULL' );
 $stmt->bindParam(':AantalBezet',           ($opleiding['AantalBezet']) ? $opleiding['AantalBezet'] : 'NULL' );
 $stmt->bindParam(':AantalVrij',            ($opleiding['AantalVrij']) ? $opleiding['AantalVrij'] : 'NULL' );
 $stmt->bindParam(':IsAantalVrijNull',      ($opleiding['IsAantalVrijNull']) ? $opleiding['IsAantalVrijNull'] : 'NULL' );
 $stmt->bindParam(':MinCursisten',          ($opleiding['MinCursisten']) ? $opleiding['MinCursisten'] : 'NULL' );
 $stmt->bindParam(':IsMinCursistenNull',    ($opleiding['IsMinCursistenNull']) ? $opleiding['IsMinCursistenNull'] : 'NULL' );
 $stmt->bindParam(':MaxCursisten',          ($opleiding['MaxCursisten']) ? $opleiding['MaxCursisten'] : 'NULL' );
 $stmt->bindParam(':IsMaxCursistenNull',    ($opleiding['IsMaxCursistenNull']) ? $opleiding['IsMaxCursistenNull'] : 'NULL' );
 $stmt->bindParam(':Opmerking',             ($opleiding['Opmerking']) ? $opleiding['Opmerking'] : 'NULL' );
 $stmt->bindParam(':ContactPersonId',       ($opleiding['ContactPersonId']) ? $opleiding['ContactPersonId'] : 'NULL' );
 $stmt->bindParam(':ContactPersonNaam',     ($opleiding['ContactPersonNaam']) ? $opleiding['ContactPersonNaam'] : 'NULL' );
 $stmt->bindParam(':ContactPerson2Id',      ($opleiding['ContactPerson2Id']) ? $opleiding['ContactPerson2Id'] : 'NULL' );
 $stmt->bindParam(':ContactPerson2Naam',    ($opleiding['ContactPerson2Naam']) ? $opleiding['ContactPerson2Naam'] : 'NULL' );
 $stmt->bindParam(':OpleidingStatusId',     ($opleiding['OpleidingStatusId']) ? $opleiding['OpleidingStatusId'] : 'NULL' );
 $stmt->bindParam(':OpleidingStatusNaam',   ($opleiding['OpleidingStatusNaam']) ? $opleiding['OpleidingStatusNaam'] : 'NULL' );
 $stmt->bindParam(':PublicatieWebsite',     ($opleiding['PublicatieWebsite']) ? $opleiding['PublicatieWebsite'] : 'NULL' );
 $stmt->bindParam(':PublicatiePlanning',    ($opleiding['PublicatiePlanning']) ? $opleiding['PublicatiePlanning'] : 'NULL' );
 $stmt->bindParam(':Planningstype',         ($opleiding['Planningstype']) ? $opleiding['Planningstype'] : 'NULL' );
 $stmt->bindParam(':PlanningsfrequentieAantal',        ($opleiding['Planningsfrequentie_aantal']) ? $opleiding['Planningsfrequentie_aantal'] : 'NULL' );
 $stmt->bindParam(':PlanningsfrequentieTijdseenheid',  ($opleiding['Planningsfrequentie_tijdseenheid']) ? $opleiding['Planningsfrequentie_tijdseenheid'] : 'NULL' );
 $stmt->bindParam(':PlanningWeekdagen',                 ($opleiding['PlanningWeekdagen']) ? $opleiding['PlanningWeekdagen'] : 'NULL' );
 $stmt->bindParam(':PlanningConflictafhandeling',       ($opleiding['PlanningConflictafhandeling']) ? $opleiding['PlanningConflictafhandeling'] : 'NULL' );
 $stmt->bindParam(':TotAantalUur',                      ($opleiding['TotAantalUur']) ? $opleiding['TotAantalUur'] : 'NULL' );
 $stmt->bindParam(':TotStudieBelasting',                ($opleiding['TotStudieBelasting']) ? $opleiding['TotStudieBelasting'] : 'NULL' );
 $stmt->bindParam(':TotAantalOnderdelen',               ($opleiding['TotAantalOnderdelen']) ? $opleiding['TotAantalOnderdelen'] : 'NULL' );

I'd love to know what I'm doing wrong. 39 params in the query, 39 params being bound.

Pardon my whitespacing, I've been doing this for a while and I used the tab spacing to be able to look at things more evenly.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Rizky Fakkel
  • 8,703
  • 1
  • 14
  • 20
  • 1
    if you cannot handle named parameters, go for positional ones. – Your Common Sense Jan 28 '17 at 13:27
  • 1
    Of course we have no idea how many columns there are on the table and how many of those are allowed a default value etc etc – RiggsFolly Jan 28 '17 at 13:28
  • 1
    The names in the bind_param have to match the placeholder names in the VALUE list. I am not going to check 39 names for you. – RiggsFolly Jan 28 '17 at 13:31
  • @RiggsFolly No worries, but I already did the dirty work. But it seems like they all do match, I've gone over this for around 4 hours now repeating the process of checking every single param. Including an auto_increment id column, there's 40 columns. 39 are shown above, and there's 39 bindParam lines. It's really confusing me now. – Rizky Fakkel Jan 28 '17 at 13:36
  • @YourCommonSense I guess that's how I'll have to try it. Also, the article you referred this as duplicate to is about Yii. It doesn't really work for me cause I've checked points 1 and 2 from the given answer there in my code multiple times. – Rizky Fakkel Jan 28 '17 at 13:38
  • 1
    I note you have an option to set all fields to NULL if a value s not present in the variable. Are you setting a column to NULL that is not allowed to be NULL – RiggsFolly Jan 28 '17 at 13:40
  • @RiggsFolly aside from the 'id' column, all fields are able to be NULL. – Rizky Fakkel Jan 28 '17 at 13:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134251/discussion-between-rizky-fakkel-and-riggsfolly). – Rizky Fakkel Jan 28 '17 at 13:52
  • @YourCommonSense Thank you, your suggestion worked. Guess RiggsFolly was still right and there must have been a typo somewhere. – Rizky Fakkel Jan 28 '17 at 14:09

0 Answers0