Call Oracle stored procedure using PDO PHP - php

I want to call procedure(written to insert data in table) using PDO PHP
,But procedure is not getting called.Don't know what Am I doing wrong
Below is my code,Can anyone suggest me best way to call Oracle Procedure using PDO PHP.
<?php
require("connection.php");
date_default_timezone_set('Asia/Kolkata');
$PARTY_C = 36317;
$CONN_NO = 479;
$EST_C = 86;
$STATUS = 'F';
$FAULTY_STATUS = 'PM';
$BILL_DT = date('d/m/Y');
$CURR_READ = 1000;
$PENALTY = 35;
$ADJSTMNT = 245;
$MTR_CHNG_DT = date('d/m/Y');
$OLD_MTR_READ = 900;
$METER_RES_DT = date('d/m/Y');
$PREV_OS_A_M = 1;
$PREV_INT_A_M = 34;
$PREV_PI_A_M = 45745;
$PARTY_M = 'abc';
$stmt = $conn->prepare("CALL PH_STATUS(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bindParam(1, $PARTY_C, PDO::PARAM_INT);
$stmt->bindParam(2, $CONN_NO, PDO::PARAM_INT);
$stmt->bindParam(3, $EST_C, PDO::PARAM_INT);
$stmt->bindParam(4, $STATUS, PDO::PARAM_STR);
$stmt->bindParam(5, $FALTY_STATUS, PDO::PARAM_STR);
$stmt->bindParam(6, $BILL_DT, PDO::PARAM_STR);
$stmt->bindParam(7, $CURR_READ, PDO::PARAM_INT);
$stmt->bindParam(8, $PENALTY, PDO::PARAM_INT);
$stmt->bindParam(9, $ADJSTMNT, PDO::PARAM_INT);
$stmt->bindParam(10, $MTR_CHNG_DT, PDO::PARAM_STR);
$stmt->bindParam(11, $OLD_MTR_READ, PDO::PARAM_INT);
$stmt->bindParam(12, $METER_RES_DT, PDO::PARAM_STR);
$stmt->bindParam(13, $PREV_OS_A_M, PDO::PARAM_INT);
$stmt->bindParam(14, $PREV_INT_A_M, PDO::PARAM_INT);
$stmt->bindParam(15, $PREV_PI_A_M, PDO::PARAM_INT);
$stmt->bindParam(16, $PARTY_M, PDO::PARAM_STR);
$stmt->execute();
print "procedure returned $stmt\n";
?>

As found here http://php.net/manual/en/pdo.prepared-statements.php, you have to use the bindParameter in another way or you have to use bindValue. (A good explanation can be found here Using pdo in php with stored procedure)
This should work:
...
$stmt->bindValue(1, $PARTY_C, PDO::PARAM_INT);
$stmt->bindValue(2, $CONN_NO, PDO::PARAM_INT);
$stmt->bindValue(3, $EST_C, PDO::PARAM_INT);
...

Related

I have got the same mistake frm PDO PHP

I use PHP PDO to update my data n database, but htis nt work coretly i still recive te same errror:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number.
how cna i fix this?
Hello I stil received this error but i can not find a mistake i made. when i throw away execute the code do not throw any error, but nothing change in my database.
I create code that should update a data in database i still receives this error:
I really want to now what make this error and hot to fixed i check with manual and everything look find, and i do not find any cntaradiction with my database in sql ask.
<?php
session_start();
include 'polaczenie_baz_danych.php';
$id_faktury = $_POST['id_faktury'];
$id_sprzedawcy = $_POST['id_sprzedawcy'];
$id_nabywcy = $_POST['id_nabywcy'];
if(isset($_POST['submit']))
{
$numer_faktury = $_POST['numer_faktury'];
$typ_faktury = $_POST['typ_faktury'];
$miejsce_wystawienia = $_POST['miejsce_wystawienia'];
$termin_wystawienia = $_POST['termin_wystawienia'];
$termin_sprzedazy= $_POST['termin_sprzedazy'];
$status_faktury = $_POST['status_faktury'];
$sposob_platnosci = $_POST['sposob_platnosci'];
$termin_platnosci = $_POST['termin_platnosci'];
$numer_konta = $_POST['numer_konta'];
$towar_usluga = $_POST['towar_usluga'];
$jm = $_POST['jm'];
$ilosc = $_POST['ilosc'];
$cena_netto = $_POST['cena_netto'];
$wartosc_netto = $_POST['wartosc_netto'];
$stawka_vat = $_POST['stawka_vat'];
$kwota_vat = $_POST['kwota_vat'];
$wartosc_brutto = $_POST['wartosc_brutto'];
$nazwa_nabywcy = $_POST['nazwa_nabywcy'];
$nip_nabywcy = $_POST['nip_nabywcy'];
$adres_nabywcy = $_POST['adres_nabywcy'];
$miasto_nabywcy = $_POST['miasto_nabywcy'];
$kod_pocztowy_nabywcy = $_POST['kod_pocztowy_nabywcy'];
$nazwa_sprzedawcy = $_POST['nazwa_sprzedawcy'];
$nip_sprzedawcy = $_POST['nip_sprzedawcy'];
$adres_sprzedawcy = $_POST['adres_sprzedawcy'];
$miasto_sprzedawcy = $_POST['miasto_sprzedawcy'];
$kod_pocztowy_sprzedawcy = $_POST['kod_pocztowy_sprzedawcy'];
$sql1 = ('UPDATE faktury SET
typ_faktury=:typ_faktury,
termin_wystawienia=:termin_wystawienia,
miejsce_wystawienia=:miejsce_wystawienia,
numer_faktury=:numer_faktury,
termin_sprzedazy=:termin_sprzedazy,
towar_usluga=:towar_usluga,
jm=:jm,
ilosc=:ilosc,
cena_netto=:cena_netto,
wartosc_netto=:wartosc_netto,
stawka_vat=:stawka_vat,
kwota_vat=:kwota_vat,
wartosc_brutto=:wartosc_brutto,
status_faktury=:status_faktury,
termin_platnosci=:termin_platnosci,
sposob_platnosci=:sposob_platnosci,
numer_konta=:numer_konta
WHERE id_faktury=:id_faktury');
$sql2 = ('UPDATE nabywcy SET nazwa_nabywcy=:nazwa_nabywcy,
nip_nabywcy=:nip_nabywcy,
adres_nabywcy=:adres_nabywcy,
miasto_nabywcy=:miasto_nabywcy,
kod_pocztowy_nabywcy=:kod_pocztowy_nabywcy
WHERE id_nabywcy=:id_nabywcy');
$sql3 =('UPDATE sprzedawcy SET nazwa_sprzedawcy=:nazwa_sprzedawcy, nip_sprzedawcy=:nip_sprzedawcy, adres_sprzedawcy=:adres_sprzedawcy, miasto_sprzedawcy=:miasto_sprzedawcy, kod_pocztowy_sprzedawcy=:kod_pocztowy_sprzedawcy
WHERE id_sprzedawcy=:id_sprzedawcy');
$performsql1 = $db->prepare($sql1);
$performsql1->bindValue(':typ_faktury',$typ_faktury, PDO::PARAM_STR);
$performsql1->bindValue(':termin_wystawienia',$termin_wystawienia, PDO::PARAM_STR);
$performsql1->bindValue(':miejsce_wystawienia',$miejsce_wystawienia, PDO::PARAM_STR);
$performsql1->bindValue(':numer_faktury',$numer_faktury, PDO::PARAM_STR);
$performsql1->bindValue(':termin_sprzedazy',$termin_sprzedazy, PDO::PARAM_STR);
$performsql1->bindValue(':towar_usluga', $towar_usluga, PDO::PARAM_STR);
$performsql1->bindValue(':jm',$jm, PDO::PARAM_STR);
$performsql1->bindValue(':ilosc',$ilosc, PDO::PARAM_INT);
$performsql1->bindValue(':cena_netto',$cena_netto, PDO::PARAM_STR);
$performsql1->bindValue(':wartosc_netto',($wartosc_netto), PDO::PARAM_STR);
$performsql1->bindValue(':stawka_vat',$stawka_vat, PDO::PARAM_STR);
$performsql1->bindValue(':kwota_vat',$kwota_vat, PDO::PARAM_STR);
$performsql1->bindValue(':wartosc_brutto',$wartosc_brutto, PDO::PARAM_STR);
$performsql1->bindValue(':sposob_platnosci',$sposob_platnosci, PDO::PARAM_STR);
$performsql1->bindValue(':status_faktury',$status_faktury, PDO::PARAM_STR);
$performsql1->bindValue(':termin_platnosci',$termin_platnosci, PDO::PARAM_STR);
$performsql1->bindValue(':numer_konta',$numer_konta, PDO::PARAM_STR);
$performsql1->bindValue(':id_faktury',$id_faktury, PDO::PARAM_INT);
$performsql1->execute();
unset($sql1);
$performsql2 = $db->prepare($sql2);
$performsql2->bindValue(':nazwa_nabywcy',$nazwa_nabywcy, PDO::PARAM_STR);
$performsql2->bindValue(':nip_nabywcy',$nip_nabywcy, PDO::PARAM_STR);
$performsql2->bindValue(':adres_nabywcy',$adres_nabywcy, PDO::PARAM_STR);
$performsql2->bindValue(':miasto_nabywcy',$miasto_nabywcy, PDO::PARAM_STR);
$performsql2->bindValue(':kod_pocztowy_nabywcy', $kod_pocztowy_nabywcy, PDO::PARAM_STR);
$performsql1->bindValue(':id_nabywcy',$id_nabywcy, PDO::PARAM_INT);
$performsql2->execute();
unset($sql2);
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
$performsql3 = $db->prepare($sql3);
$performsql3->bindValue(':nazwa_sprzedawcy',$nazwa_sprzedawcy, PDO::PARAM_STR);
$performsql3->bindValue(':nip_sprzedawcy',$nip_sprzedawcy, PDO::PARAM_STR);
$performsql3->bindValue(':adres_sprzedawcy',$adres_sprzedawcy, PDO::PARAM_STR);
$performsql3->bindValue(':miasto_sprzedawcy',$miasto_sprzedawcy, PDO::PARAM_STR);
$performsql3->bindValue(':kod_pocztowy_sprzedawcy', $kod_pocztowy_sprzedawcy, PDO::PARAM_STR);
$performsql1->bindValue(':id_sprzedawcy',$id_sprzedawcy, PDO::PARAM_NT);
$performsq3->execute();
unset($sql3);
}
?>
In $sql1 you have 18 parameters, but in $performsql1 you have only 17 bindings. You have lost 1 value to bind.
Upd.
You have WHERE id_faktury=:id_faktury' - it's 18th parameter. You have lost value ':id_faktury' to bind.

Is it possible to optimize a large amount of BindValue in PDO by means of loops?

I have website with sudoku. Users can save their sudoku's to finish later. I would like to optimize or shorten my code. a1, a2, a3...[...] are the "name" of the individual fields in sudoku. I use PDO library.
This is the php code that saves all sudoku fields to the database:
$query = $db->prepare("INSERT INTO rozw
(user_id, id_wynik,
a1, a2, a3, a4, a5, a6, a7, a8, a9,
b1, b2, b3, b4, b5, b6, b7, b8, b9,
c1, c2, c3, c4, c5, c6, c7, c8, c9,
d1, d2, d3, d4, d5, d6, d7, d8, d9,
e1, e2, e3, e4, e5, e6, e7, e8, e9,
f1, f2, f3, f4, f5, f6, f7, f8, f9,
g1, g2, g3, g4, g5, g6, g7, g8, g9,
h1, h2, h3, h4, h5, h6, h7, h8, h9,
i1, i2, i3, i4, i5, i6, i7, i8, i9)
VALUES (:user_id, :id_wynik,
:a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9,
:b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8, :b9,
:c1, :c2, :c3, :c4, :c5, :c6, :c7, :c8, :c9,
:d1, :d2, :d3, :d4, :d5, :d6, :d7, :d8, :d9,
:e1, :e2, :e3, :e4, :e5, :e6, :e7, :e8, :e9,
:f1, :f2, :f3, :f4, :f5, :f6, :f7, :f8, :f9,
:g1, :g2, :g3, :g4, :g5, :g6, :g7, :g8, :g9,
:h1, :h2, :h3, :h4, :h5, :h6, :h7, :h8, :h9,
:i1, :i2, :i3, :i4, :i5, :i6, :i7, :i8, :i9)");
$query->bindValue(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$query->bindValue(':id_wynik', $_POST['id_wynik'], PDO::PARAM_INT);
$query->bindValue(':a1', $_POST['a1'], PDO::PARAM_INT);
$query->bindValue(':a2', $_POST['a2'], PDO::PARAM_INT);
$query->bindValue(':a3', $_POST['a3'], PDO::PARAM_INT);
$query->bindValue(':a4', $_POST['a4'], PDO::PARAM_INT);
$query->bindValue(':a5', $_POST['a5'], PDO::PARAM_INT);
$query->bindValue(':a6', $_POST['a6'], PDO::PARAM_INT);
$query->bindValue(':a7', $_POST['a7'], PDO::PARAM_INT);
$query->bindValue(':a8', $_POST['a8'], PDO::PARAM_INT);
$query->bindValue(':a9', $_POST['a9'], PDO::PARAM_INT);
$query->bindValue(':b1', $_POST['b1'], PDO::PARAM_INT);
$query->bindValue(':b2', $_POST['b2'], PDO::PARAM_INT);
$query->bindValue(':b3', $_POST['b3'], PDO::PARAM_INT);
$query->bindValue(':b4', $_POST['b4'], PDO::PARAM_INT);
$query->bindValue(':b5', $_POST['b5'], PDO::PARAM_INT);
$query->bindValue(':b6', $_POST['b6'], PDO::PARAM_INT);
$query->bindValue(':b7', $_POST['b7'], PDO::PARAM_INT);
$query->bindValue(':b8', $_POST['b8'], PDO::PARAM_INT);
$query->bindValue(':b9', $_POST['b9'], PDO::PARAM_INT);
$query->bindValue(':c1', $_POST['c1'], PDO::PARAM_INT);
$query->bindValue(':c2', $_POST['c2'], PDO::PARAM_INT);
$query->bindValue(':c3', $_POST['c3'], PDO::PARAM_INT);
$query->bindValue(':c4', $_POST['c4'], PDO::PARAM_INT);
$query->bindValue(':c5', $_POST['c5'], PDO::PARAM_INT);
$query->bindValue(':c6', $_POST['c6'], PDO::PARAM_INT);
$query->bindValue(':c7', $_POST['c7'], PDO::PARAM_INT);
$query->bindValue(':c8', $_POST['c8'], PDO::PARAM_INT);
$query->bindValue(':c9', $_POST['c9'], PDO::PARAM_INT);
$query->bindValue(':d1', $_POST['d1'], PDO::PARAM_INT);
$query->bindValue(':d2', $_POST['d2'], PDO::PARAM_INT);
$query->bindValue(':d3', $_POST['d3'], PDO::PARAM_INT);
$query->bindValue(':d4', $_POST['d4'], PDO::PARAM_INT);
$query->bindValue(':d5', $_POST['d5'], PDO::PARAM_INT);
$query->bindValue(':d6', $_POST['d6'], PDO::PARAM_INT);
$query->bindValue(':d7', $_POST['d7'], PDO::PARAM_INT);
$query->bindValue(':d8', $_POST['d8'], PDO::PARAM_INT);
$query->bindValue(':d9', $_POST['d9'], PDO::PARAM_INT);
$query->bindValue(':e1', $_POST['e1'], PDO::PARAM_INT);
$query->bindValue(':e2', $_POST['e2'], PDO::PARAM_INT);
$query->bindValue(':e3', $_POST['e3'], PDO::PARAM_INT);
$query->bindValue(':e4', $_POST['e4'], PDO::PARAM_INT);
$query->bindValue(':e5', $_POST['e5'], PDO::PARAM_INT);
$query->bindValue(':e6', $_POST['e6'], PDO::PARAM_INT);
$query->bindValue(':e7', $_POST['e7'], PDO::PARAM_INT);
$query->bindValue(':e8', $_POST['e8'], PDO::PARAM_INT);
$query->bindValue(':e9', $_POST['e9'], PDO::PARAM_INT);
$query->bindValue(':f1', $_POST['f1'], PDO::PARAM_INT);
$query->bindValue(':f2', $_POST['f2'], PDO::PARAM_INT);
$query->bindValue(':f3', $_POST['f3'], PDO::PARAM_INT);
$query->bindValue(':f4', $_POST['f4'], PDO::PARAM_INT);
$query->bindValue(':f5', $_POST['f5'], PDO::PARAM_INT);
$query->bindValue(':f6', $_POST['f6'], PDO::PARAM_INT);
$query->bindValue(':f7', $_POST['f7'], PDO::PARAM_INT);
$query->bindValue(':f8', $_POST['f8'], PDO::PARAM_INT);
$query->bindValue(':f9', $_POST['f9'], PDO::PARAM_INT);
$query->bindValue(':g1', $_POST['g1'], PDO::PARAM_INT);
$query->bindValue(':g2', $_POST['g2'], PDO::PARAM_INT);
$query->bindValue(':g3', $_POST['g3'], PDO::PARAM_INT);
$query->bindValue(':g4', $_POST['g4'], PDO::PARAM_INT);
$query->bindValue(':g5', $_POST['g5'], PDO::PARAM_INT);
$query->bindValue(':g6', $_POST['g6'], PDO::PARAM_INT);
$query->bindValue(':g7', $_POST['g7'], PDO::PARAM_INT);
$query->bindValue(':g8', $_POST['g8'], PDO::PARAM_INT);
$query->bindValue(':g9', $_POST['g9'], PDO::PARAM_INT);
$query->bindValue(':h1', $_POST['h1'], PDO::PARAM_INT);
$query->bindValue(':h2', $_POST['h2'], PDO::PARAM_INT);
$query->bindValue(':h3', $_POST['h3'], PDO::PARAM_INT);
$query->bindValue(':h4', $_POST['h4'], PDO::PARAM_INT);
$query->bindValue(':h5', $_POST['h5'], PDO::PARAM_INT);
$query->bindValue(':h6', $_POST['h6'], PDO::PARAM_INT);
$query->bindValue(':h7', $_POST['h7'], PDO::PARAM_INT);
$query->bindValue(':h8', $_POST['h8'], PDO::PARAM_INT);
$query->bindValue(':h9', $_POST['h9'], PDO::PARAM_INT);
$query->bindValue(':i1', $_POST['i1'], PDO::PARAM_INT);
$query->bindValue(':i2', $_POST['i2'], PDO::PARAM_INT);
$query->bindValue(':i3', $_POST['i3'], PDO::PARAM_INT);
$query->bindValue(':i4', $_POST['i4'], PDO::PARAM_INT);
$query->bindValue(':i5', $_POST['i5'], PDO::PARAM_INT);
$query->bindValue(':i6', $_POST['i6'], PDO::PARAM_INT);
$query->bindValue(':i7', $_POST['i7'], PDO::PARAM_INT);
$query->bindValue(':i8', $_POST['i8'], PDO::PARAM_INT);
$query->bindValue(':i9', $_POST['i9'], PDO::PARAM_INT);
$query->execute();
Can I shorten this code somehow using loops? Any suggestions?
And how to do it?
This should do what you want
$query->bindValue(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$query->bindValue(':id_wynik', $_POST['id_wynik'], PDO::PARAM_INT);
$alpha = ['a','b','c','d','e','f','g','h','i'];
$max = 9;
foreach ($alpha as $a){
for ($n=1; $n<=$max; $n++) {
$query->bindValue(":$a$n", $_POST[$a$n], PDO::PARAM_INT);
}
}
You can pass an associative array as a parameter to the execute method:
$data = [
':user_id' => $_SESSION['user_id'],
':id_wynik' => $_POST['id_wynik'],
];
foreach (range('a', 'i') as $row) {
foreach (range(1, 9) as $col) {
$key = $row . $col;
$data[$key] = $_POST[$key];
}
}
$query->execute($data);
$colNames = '';
$colValus = '';
$charArray = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
foreach($charArray as $key => $char)
{
for($i=1; $i<=9; $i++)
{
$colNames .= ',' . $char . $i;
$colValues .= ':' . $char . $i;
}
}
$sqlQuery = 'INSERT INTO rozw (user_id, id_wynik, ' . $colNames . ' VALUES (:user_id, :id_wynik, ' . $colValues . '))';
$query->bindValue(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
$query->bindValue(':id_wynik', $_POST['id_wynik'], PDO::PARAM_INT);
foreach($charArray as $key => $char)
{
for($i=1; $i<=9; $i++)
{
$colVal = ':' . $char . $i;
$postVal = $char . $i;
$query->bindValue($colVal , $_POST[$postVal], PDO::PARAM_INT);
}
}
$query->execute();

inserting date using PDO and php

I'm trying to insert into a table, I have managed this using the same syntax for another query but this fails, the only difference is that this contains date information. Can anyone spot the problem?
The date is in this format: 2016-07-07.
try {
$sql2 = "INSERT INTO excavation.contexts_spatial
(area_easting,
area_northing,
context_number,
open_date,
close_date,
excavation_method,
contamination,
zooarchaeology_comments,
ceramic_comments) VALUES (
:area_easting,
:area_northing,
:context_number,
:open_date,
:close_date,
:excavation_method,
:contamination,
:zooarchaeology_comments,
:ceramic_comments)";
$stmt2 = $conn->prepare($sql2);
// prepare sql and bind parameters
$stmt2->bindParam(':area_easting', $area_easting, PDO::PARAM_INT);
$stmt2->bindParam(':area_northing', $area_northing, PDO::PARAM_INT);
$stmt2->bindParam(':context_number', $nextContext, PDO::PARAM_INT);
$stmt2->bindParam(':open_date', $open_date, PDO::PARAM_STR);
$stmt2->bindParam(':close_date', $close_date, PDO::PARAM_STR);
$stmt2->bindParam(':excavation_method', $excavation_method, PDO::PARAM_STR);
$stmt2->bindParam(':contamination', $contamination, PDO::PARAM_STR);
$stmt2->bindParam(':zooarchaeology_comments', $excavation_method, PDO::PARAM_STR);
$stmt2->bindParam(':ceramic_comments', $excavation_method, PDO::PARAM_STR);
//$stmt2->execute();
// insert a row
$area_easting = $_SESSION['area_easting'];
$area_northing = $_SESSION['area_northing'];
$nextContext = $_SESSION['nextContext'];
$open_date = $_SESSION['dateOpen'];
$close_date = $_SESSION['dateClose'];
$excavation_method = $_SESSION['excavationMethod'];
$contamination = $_SESSION['contamination'];
$zooarchaeology_comments = $_SESSION['zooarchaeologyComments'];
$ceramic_comments = $_SESSION['ceramicComments'];
$stmt2->execute();
echo "New records created successfully in contexts spatial<br />";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
You are executing your statement before setting the variables. Remove $stmt2->execute();
from below
$stmt2->bindParam(':ceramic_comments', $excavation_method, PDO::PARAM_STR);
$stmt2->execute(); // REMOVE THIS LINE
// insert a row
$area_easting = $_SESSION['area_easting'];

Fatal error: Uncaught PDOException: SQLSTATE[HY093]

I get this error message on line 242:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 242
PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined on line 242
global $db, $id;
$malattiaPastNome = $_POST['malattia_past_nome'];
$malattiaPastDataInizio = $_POST['malattia_past_data_inizio'];
$malattiaPastDataFine = $_POST['malattia_past_data_fine'];
$malattiaPresentiNome = $_POST['malattia_presenti_nome'];
$interventiTraumi = $_REQUEST['interventi_traumi'];
$interventiTraumiAltro = $_POST['interventi_traumi_altro'];
$interventiTraumiData = $_POST['interventi_traumi_data'];
$sintomiAttualiNome = $_REQUEST['sintomi_attuali_nome'];
$sintomiAttualiNomeAltro = $_POST['sintomi_attuali_nome_altro'];
$sintomiAttualiFrequenza = $_REQUEST['sintomi_attuali_frequenza'];
$sintomiAttualiDurata = $_REQUEST['sintomi_attuali_durata'];
$sintomiAttualiIntensita = $_REQUEST['sintomi_attuali_intensita'];
$alimQuotidColazione = $_REQUEST['alim_quotid_colazione'];
$alimQuotidColazioneBevande = $_REQUEST['alim_quotid_colazione_bevande'];
$alimQuotidColazioneAlimenti = $_REQUEST['alim_quotid_colazione_alimenti'];
$alimQuotidMerenda = $_REQUEST['alim_quotid_merenda'];
$alimQuotidMerendaBevande = $_REQUEST['alim_quotid_merenda_bevande'];
$alimQuotidMerendaAlimenti = $_REQUEST['alim_quotid_merenda_alimenti'];
$alimQuotidPranzo = $_REQUEST['alim_quotid_pranzo'];
$alimQuotidPranzoBevande = $_REQUEST['alim_quotid_pranzo_bevande'];
$alimQuotidPranzoAlimenti = $_REQUEST['alim_quotid_pranzo_alimenti'];
$alimQuotidPomeridiano = $_REQUEST['alim_quotid_pomeridiano'];
$alimQuotidPomeridianoBevande = $_REQUEST['alim_quotid_pomeridiano_bevande'];
$alimQuotidPomeridianoAlimenti = $_REQUEST['alim_quotid_pomeridiano_alimenti'];
$alimQuotidCena = $_REQUEST['alim_quotid_cena'];
$alimQuotidCenaBevande = $_REQUEST['alim_quotid_cena_bevande'];
$alimQuotidCenaAlimenti = $_POST['alim_quotid_cena_alimenti'];
$sql = 'UPDATE utenti2 SET malattia_past_nome=:past_nome, malattia_past_data_inizio=:past_dataInizio, malattia_past_data_fine=:past_data_fine, malattia_presenti_nome=:presenti_nome, interventi_traumi=:interventi_traumi, interventi_traumi_altro=:traumi_altro, interventi_traumi_data=:traumi_data, sintomi_attuali_nome=:attuali_nome, sintomi_attuali_nome_altro=:attuali_nome_altro, sintomi_attuali_frequenza=:attuali_frequenza, sintomi_attuali_durata=:attuali_durata, sintomi_attuali_intensita=:attuali_intensita, alim_quotid_colazione=:colazione, alim_quotid_colazione_bevande=:colazioe_bevande, alim_quotid_colazione_alimenti=:colazione_alimenti, alim_quotid_merenda=:merenda, alim_quotid_merenda_bevande=:merenda_bevande, alim_quotid_merenda_alimenti=:merenda_alimenti, alim_quotid_pranzo=:_pranzo, alim_quotid_pranzo_bevande=:pranzo_bevande, alim_quotid_pranzo_alimenti=:pranzo_alimenti, alim_quotid_pomeridiano=:pomeridiano, alim_quotid_pomeridiano_bevande=:pomeridiano_bevande, alim_quotid_pomeridiano_alimenti=:pomeridiano_alimenti, alim_quotid_cena=:cena, alim_quotid_cena_bevande=:bevande, alim_quotid_cena_alimenti=:cena_alimenti WHERE id=:id LIMIT 1';
$result = $db->prepare($sql);
$result->bindValue(':id', $id, PDO::PARAM_INT);
$result->bindValue(':past_nome', $malattiaPastNome, PDO::PARAM_STR);
$result->bindValue(':past_dataInizio', $malattiaPastDataInizio, PDO::PARAM_STR);
$result->bindValue(':past_data_fine', $malattiaPastDataFine, PDO::PARAM_STR);
$result->bindValue(':presenti_nome', $malattiaPresentiNome, PDO::PARAM_STR);
$result->bindValue(':interventi_traumi', $interventiTraumi, PDO::PARAM_STR);
$result->bindValue(':traumi_altro', $interventiTraumiAltro, PDO::PARAM_STR);
$result->bindValue(':traumi_data', $interventiTraumiData, PDO::PARAM_STR);
$result->bindValue(':attuali_nome', $sintomiAttualiNome, PDO::PARAM_STR);
$result->bindValue(':attuali_nome_altro', $sintomiAttualiNomeAltro, PDO::PARAM_STR);
$result->bindValue(':attuali_frequenza', $sintomiAttualiFrequenza, PDO::PARAM_STR);
$result->bindValue(':attuali_durata', $sintomiAttualiDurata, PDO::PARAM_STR);
$result->bindValue(':attuali_intensita', $sintomiAttualiIntensita, PDO::PARAM_STR);
$result->bindValue(':colazione', $alimQuotidColazione, PDO::PARAM_STR);
$result->bindValue(':colazione_bevande', $alimQuotidColazioneBevande, PDO::PARAM_STR);
$result->bindValue(':colazione_alimenti', $alimQuotidColazioneAlimenti, PDO::PARAM_STR);
$result->bindValue(':merenda', $alimQuotidMerenda, PDO::PARAM_STR);
$result->bindValue(':merenda_bevande', $alimQuotidMerendaBevande, PDO::PARAM_STR);
$result->bindValue(':merenda_alimenti', $alimQuotidMerendaAlimenti, PDO::PARAM_STR);
$result->bindValue(':pranzo', $alimQuotidPranzo, PDO::PARAM_STR);
$result->bindValue(':pranzo_bevande', $alimQuotidPranzoBevande, PDO::PARAM_STR);
$result->bindValue(':pranzo_alimenti', $alimQuotidPranzoAlimenti, PDO::PARAM_STR);
$result->bindValue(':pomeridiano', $alimQuotidPomeridiano, PDO::PARAM_STR);
$result->bindValue(':pomeridiano_bevande', $alimQuotidPomeridianoBevande, PDO::PARAM_STR);
$result->bindValue(':pomeridiano_alimenti', $alimQuotidPomeridianoAlimenti, PDO::PARAM_STR);
$result->bindValue(':cena', $alimQuotidCena, PDO::PARAM_STR);
$result->bindValue(':cena_bevande', $alimQuotidCenaBevande, PDO::PARAM_STR);
$result->bindValue(':cena_alimenti', $alimQuotidCenaAlimenti, PDO::PARAM_STR);
$result->execute(); //line 242
I tried multiple times checking all my vars and code but can't find the error.
Thanks
You may have a typo in one of your bindParams, which means you have a mismatch in parameters.Please check and confirm
This query is not correct (or at least i don't know a possible way to use limit in UPDATE queries). So remove LIMIT 1 from the query and try again
You have used with name past_data_fine in query but while binding you used variable as past_dataFine . so
repalce your line:
$result->bindValue(':past_dataFine', $malattiaPastDataFine, PDO::PARAM_STR);
with
$result->bindValue(':past_data_fine', $malattiaPastDataFine, PDO::PARAM_STR);
Final version working:
global $db, $id;
$malattiaPastNome = $_POST['malattia_past_nome'];
$malattiaPastDataInizio = $_POST['malattia_past_data_inizio'];
$malattiaPastDataFine = $_POST['malattia_past_data_fine'];
$malattiaPresentiNome = $_POST['malattia_presenti_nome'];
$interventiTraumi = $_REQUEST['interventi_traumi'];
$interventiTraumiAltro = $_POST['interventi_traumi_altro'];
$interventiTraumiData = $_POST['interventi_traumi_data'];
$sintomiAttualiNome = $_REQUEST['sintomi_attuali_nome'];
$sintomiAttualiNomeAltro = $_POST['sintomi_attuali_nome_altro'];
$sintomiAttualiFrequenza = $_REQUEST['sintomi_attuali_frequenza'];
$sintomiAttualiDurata = $_REQUEST['sintomi_attuali_durata'];
$sintomiAttualiIntensita = $_REQUEST['sintomi_attuali_intensita'];
$alimQuotidColazione = $_REQUEST['alim_quotid_colazione'];
$alimQuotidColazioneBevande = $_REQUEST['alim_quotid_colazione_bevande'];
$alimQuotidColazioneAlimenti = $_REQUEST['alim_quotid_colazione_alimenti'];
$alimQuotidMerenda = $_REQUEST['alim_quotid_merenda'];
$alimQuotidMerendaBevande = $_REQUEST['alim_quotid_merenda_bevande'];
$alimQuotidMerendaAlimenti = $_REQUEST['alim_quotid_merenda_alimenti'];
$alimQuotidPranzo = $_REQUEST['alim_quotid_pranzo'];
$alimQuotidPranzoBevande = $_REQUEST['alim_quotid_pranzo_bevande'];
$alimQuotidPranzoAlimenti = $_REQUEST['alim_quotid_pranzo_alimenti'];
$alimQuotidPomeridiano = $_REQUEST['alim_quotid_pomeridiano'];
$alimQuotidPomeridianoBevande = $_REQUEST['alim_quotid_pomeridiano_bevande'];
$alimQuotidPomeridianoAlimenti = $_REQUEST['alim_quotid_pomeridiano_alimenti'];
$alimQuotidCena = $_REQUEST['alim_quotid_cena'];
$alimQuotidCenaBevande = $_REQUEST['alim_quotid_cena_bevande'];
$alimQuotidCenaAlimenti = $_POST['alim_quotid_cena_alimenti'];
$sql = 'UPDATE utenti2 SET malattia_past_nome=:past_nome , malattia_past_data_inizio=:past_data_inizio , malattia_past_data_fine=:past_data_fine , malattia_presenti_nome=:presenti_nome , interventi_traumi=:interventi_traumi , interventi_traumi_altro=:traumi_altro , interventi_traumi_data=:traumi_data , sintomi_attuali_nome=:attuali_nome , sintomi_attuali_nome_altro=:attuali_nomea , sintomi_attuali_frequenza=:attuali_frequenza , sintomi_attuali_durata=:attuali_durata , sintomi_attuali_intensita=:attuali_intensita , alim_quotid_colazione=:colazione , alim_quotid_colazione_bevande=:colazione_bevande , alim_quotid_colazione_alimenti=:colazione_alimenti , alim_quotid_merenda=:merenda , alim_quotid_merenda_bevande=:merenda_bevande , alim_quotid_merenda_alimenti=:merenda_alimenti , alim_quotid_pranzo=:pranzo , alim_quotid_pranzo_bevande=:pranzo_bevande , alim_quotid_pranzo_alimenti=:pranzo_alimenti , alim_quotid_pomeridiano=:pomeridiano , alim_quotid_pomeridiano_bevande=:pomeridiano_bevande , alim_quotid_pomeridiano_alimenti=:pomeridiano_alimenti , alim_quotid_cena=:cena , alim_quotid_cena_bevande=:cena_bevande , alim_quotid_cena_alimenti=:cena_alimenti WHERE id=:id LIMIT 1';
$result = $db->prepare($sql);
$result->bindValue(':id', $id, PDO::PARAM_INT);
$result->bindValue(':past_nome', $malattiaPastNome, PDO::PARAM_STR);
$result->bindValue(':past_data_inizio', $malattiaPastDataInizio, PDO::PARAM_STR);
$result->bindValue(':past_data_fine', $malattiaPastDataFine, PDO::PARAM_STR);
$result->bindValue(':presenti_nome', $malattiaPresentiNome, PDO::PARAM_STR);
$result->bindValue(':interventi_traumi', $interventiTraumi, PDO::PARAM_STR);
$result->bindValue(':traumi_altro', $interventiTraumiAltro, PDO::PARAM_STR);
$result->bindValue(':traumi_data', $interventiTraumiData, PDO::PARAM_STR);
$result->bindValue(':attuali_nome', $sintomiAttualiNome, PDO::PARAM_STR);
$result->bindValue(':attuali_nomea', $sintomiAttualiNomeAltro, PDO::PARAM_STR);
$result->bindValue(':attuali_frequenza', $sintomiAttualiFrequenza, PDO::PARAM_STR);
$result->bindValue(':attuali_durata', $sintomiAttualiDurata, PDO::PARAM_STR);
$result->bindValue(':attuali_intensita', $sintomiAttualiIntensita, PDO::PARAM_STR);
$result->bindValue(':colazione', $alimQuotidColazione, PDO::PARAM_STR);
$result->bindValue(':colazione_bevande', $alimQuotidColazioneBevande, PDO::PARAM_STR);
$result->bindValue(':colazione_alimenti', $alimQuotidColazioneAlimenti, PDO::PARAM_STR);
$result->bindValue(':merenda', $alimQuotidMerenda, PDO::PARAM_STR);
$result->bindValue(':merenda_bevande', $alimQuotidMerendaBevande, PDO::PARAM_STR);
$result->bindValue(':merenda_alimenti', $alimQuotidMerendaAlimenti, PDO::PARAM_STR);
$result->bindValue(':pranzo', $alimQuotidPranzo, PDO::PARAM_STR);
$result->bindValue(':pranzo_bevande', $alimQuotidPranzoBevande, PDO::PARAM_STR);
$result->bindValue(':pranzo_alimenti', $alimQuotidPranzoAlimenti, PDO::PARAM_STR);
$result->bindValue(':pomeridiano', $alimQuotidPomeridiano, PDO::PARAM_STR);
$result->bindValue(':pomeridiano_bevande', $alimQuotidPomeridianoBevande, PDO::PARAM_STR);
$result->bindValue(':pomeridiano_alimenti', $alimQuotidPomeridianoAlimenti, PDO::PARAM_STR);
$result->bindValue(':cena', $alimQuotidCena, PDO::PARAM_STR);
$result->bindValue(':cena_bevande', $alimQuotidCenaBevande, PDO::PARAM_STR);
$result->bindValue(':cena_alimenti', $alimQuotidCenaAlimenti, PDO::PARAM_STR);
$result->execute();

SQLSTATE[HY093]: Invalid parameter number[ask]

Please help me! I have a trouble with error
PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in
I use the query:
public function SaveStep1($data)
$id = intval($data['id']);
$query = $this->db->prepare("UPDATE `user_general_info` SET `soname` = :soname, `last_soname` = :last_soname, `name` = :name,
`middle_name` = :middle_name, `birthday` = :birthday, `birthplace` = :birthplace, `city_code` = :city_code,
`city` = :city, `street` = :street, `house` = : house, `corp` = :corp, `litera` = :litera, `flat` = :flat WHERE `id` = :id");
$query->bindParam(":soname", $data[0], PDO::PARAM_STR);
$query->bindParam(":last_soname", $data[1], PDO::PARAM_STR);
$query->bindParam(":name", $data[2], PDO::PARAM_STR);
$query->bindParam(":middle_name", $data[4], PDO::PARAM_STR);
$query->bindParam(":birthday", $data[5], PDO::PARAM_STR);
$query->bindParam(":birthplace", $data[6], PDO::PARAM_STR);
$query->bindParam(":city_code", $data[7], PDO::PARAM_STR);
$query->bindParam(":city", $data[8], PDO::PARAM_STR);
$query->bindParam(":street", $data[9], PDO::PARAM_STR);
$query->bindParam(":house", $data[10], PDO::PARAM_STR);
$query->bindParam(":corp", $data[11], PDO::PARAM_STR);
$query->bindParam(":litera", $data[12], PDO::PARAM_STR);
$query->bindParam(":flat", $data[13], PDO::PARAM_STR);
$query->bindParam(":id", $data['id'], PDO::PARAM_INT);
//print_r($data[0]);
return $query->execute();
You have a typo in the SQL statement:
`house` = : house
should be
`house` = :house

Categories