im working on PDO's, i've been trying on this for many hours but still couldn't succeded to insert the inputs into the database. I dont get any errors, hence i get my $err -> succeded message. But no chance on inserting to database...
Would be glad if you can help.
note: about the user id, im getting the id from another table, column userid, and trying to insert it to another table, "params_user_id" column.
Here is my code :
if(isset($_POST["create"])) {
try{
$param1 = cleanInput($_POST["param1"]);
$param2 = cleanInput($_POST["param2"]);
$param3 = cleanInput($_POST["param3"]);
$param4 = cleanInput($_POST["param4"]);
$param5id = cleanInput($_POST["param5id"]);
$param6id = cleanInput($_POST["param6id"]);
$param7 = cleanInput($_POST["param7"]);
$param8id = cleanInput($_POST["param8id"]);
$param9 = cleanInput($_POST["param9"]);
$param10 = cleanInput($_POST["param10"]);
$param11 = cleanInput($_POST["param11"]);
$param12 = cleanInput($_POST["param12"]);
$param13 = cleanInput($_POST["param13"]);
$param14 = cleanInput($_POST["param14"]);
$param15 = cleanInput($_POST["param15"]);
$param16 = cleanInput($_POST["param16"]);
$param17 = cleanInput($_POST["param17"]);
$param18 = cleanInput($_POST["param18"]);
$param19 = cleanInput($_POST["param19"]);
$param20 = cleanInput($_POST["param20"]);
$param21 = cleanInput($_POST["param21"]);
$userid = $_SESSION[':userid'];
$datenow = date('Y-m-d H:i:s');
$create_params_query = "INSERT INTO `params`(`datenow`, `param1`, `param2`, `param3`, `param4`, `param5id`, `param6id`, `param7`, `param8id`, `param9`, `param10`, `param11`, `param12`, `param13`, `param14`, `param15`, `param16`, `param17`, `param18`, `param19`, `param20`, `param21`,`params_user_id`) VALUE(:datenow, :param1, :param2, :param3, :param4, :param5id, :param6id, :param7, :param8id, :param9, :param10, :param11, :param12, :param13, :param14, :param15, :param16, :param17, :param18, :param19, :param20, :param21, :userid)";
$create_params_do = $db->prepare($create_params_query);
$create_params_do -> bindParam(':datenow', $datenow, PDO::PARAM_STR);
$create_params_do -> bindParam(':param1', $param1, PDO::PARAM_STR);
$create_params_do -> bindParam(':param2', $param2, PDO::PARAM_STR);
$create_params_do -> bindParam(':param3', $param3, PDO::PARAM_STR);
$create_params_do -> bindParam(':param4', $param4, PDO::PARAM_STR);
$create_params_do -> bindParam(':param5id', $param5id, PDO::PARAM_INT);
$create_params_do -> bindParam(':param6id', $param6id, PDO::PARAM_INT);
$create_params_do -> bindParam(':param7', $param7, PDO::PARAM_STR);
$create_params_do -> bindParam(':param8id', $param8id, PDO::PARAM_INT);
$create_params_do -> bindParam(':param9', $param9, PDO::PARAM_STR);
$create_params_do -> bindParam(':param10', $param10, PDO::PARAM_STR);
$create_params_do -> bindParam(':param11', $param11, PDO::PARAM_STR);
$create_params_do -> bindParam(':param12', $param12, PDO::PARAM_STR);
$create_params_do -> bindParam(':param13', $param13, PDO::PARAM_STR);
$create_params_do -> bindParam(':param14', $param14, PDO::PARAM_STR);
$create_params_do -> bindParam(':param15', $param15, PDO::PARAM_STR);
$create_params_do -> bindParam(':param16', $param16, PDO::PARAM_STR);
$create_params_do -> bindParam(':param17', $param17, PDO::PARAM_STR);
$create_params_do -> bindParam(':param18', $param18, PDO::PARAM_STR);
$create_params_do -> bindParam(':param19', $param19, PDO::PARAM_STR);
$create_params_do -> bindParam(':param20', $param20, PDO::PARAM_STR);
$create_params_do -> bindParam(':param21', $param21, PDO::PARAM_STR);
$create_params_do->bindParam(':userid', $userid, PDO::PARAM_INT);
$create_params_do->execute() or die(print_r($create_params_do->errorInfo(), true));
//forgot to add when posting first sorry, i have that also.
}
catch(PDOException $e) {
$log->logError($e." - ".basename(__FILE__));
}
$err = "<div class=\"success\"><strong>"._("Congrats.")."</strong><br/>"._("Success.")."</div>";
}
You are missing
$create_params_do->execute();
at the end of params
Your query should be:
$create_params_query = "INSERT INTO `params`(`datenow`, `param1`, `param2`, `param3`, `param4`, `param5id`, `param6id`, `param7`, `param8id`, `param9`, `param10`, `param11`, `param12`, `param13`, `param14`, `param15`, `param16`, `param17`, `param18`, `param19`, `param20`, `param21`,`params_user_id`) VALUES(:datenow, :param1, :param2, :param3, :param4, :param5id, :param6id, :param7, :param8id, :param9, :param10, :param11, :param12, :param13, :param14, :param15, :param16, :param17, :param18, :param19, :param20, :param21, :userid)";
with VALUES not VALUE
To add to what Iorga side by default PDO is silent on errors so if you want to know what is happening, you will need to tell PDO to be noisy by setting setting PDO error_mode as show below. For your case VALUE or VALUES works (tested with MySQL 5.5). Catching the exception error will give you the really reason why it is not committing to the database.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Related
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.
Im trying to create a new row in the table 'Colaboradores' but it doesn't populate, but when i 'echo' the '$sql' with works fine along with the connection. I already check the name of the columns in the sql table. Im using MAMP as a sever
<?php
include("../../config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] === "POST") {
$nomeF = $_POST['nomeF'];
$nomeL = $_POST['nomeL'];
$Prof = $_POST['Profissao'];
$morada = $_POST['morada'];
$cod = $_POST['cod'];
$num = $_POST['num'];
$mail = $_POST['mail'];
$ordeb = $_POST['ordb'];
$orde = $_POST['orde'];
$dataI = $_POST['dataI'];
$dataF = $_POST['dataF'];
$notas1 = $_POST['notas1'];
$notas2 = $_POST['notas2'];
try
{
$db = new PDO('mysql:host=localhost;dbname=SCMMM;charset=utf8', 'root', 'root');
}
catch(Exception $e)
{
die('Error : '.$e->getMessage());
}
$sql = "INSERT INTO Colaboradores (NomeF, NomeL, Profissao, Morada, CodPostal, Telemovel, mail, precoh, precohmais, dataI, dataF, notas1, notas2)
VALUES (:nomeF, :nomeL, :Prof, :morada, :cod, :num, :mail, :ordeb, :orde, :dataI, :dataF, :notas1, :notas2)";
$stmt = $db->prepare($sql);
$stmt->bindValue('nomeF', $nomeF, PDO::PARAM_STR);
$stmt->bindValue('nomeL', $nomeL, PDO::PARAM_STR);
$stmt->bindValue('Prof', $Prof, PDO::PARAM_STR);
$stmt->bindValue('morada', $morada, PDO::PARAM_STR);
$stmt->bindValue('cod', $cod, PDO::PARAM_STR);
$stmt->bindValue('num', $num, PDO::PARAM_INT);
$stmt->bindValue('mail', $mail, PDO::PARAM_STR);
$stmt->bindValue('ordb', $ordeb, PDO::PARAM_INT);
$stmt->bindValue('orde', $orde, PDO::PARAM_INT);
$stmt->bindValue('dataI', $dataI, PDO::PARAM_STR);
$stmt->bindValue('dataF', $dataF, PDO::PARAM_STR);
$stmt->bindValue('notas1', $notas1, PDO::PARAM_STR);
$stmt->bindValue('notas2', $notas2, PDO::PARAM_STR);
$stmt->execute();
}
?>
You can easily improve your code :
Avoid symbol as ã or + in database
Avoid space in database (replace by _)
Inform yourself about OOP and PDO
Inform yourself about SQL injection, Prepare query, ...
Use a convention for your variables names, lower camelcase ? upper camelcase ? whatever but stay regular
Now try with this code
$nomeF = $_POST['nomeF'];
$nomeL = $_POST['nomeL'];
$descP = $_POST['descP'];
$morada = $_POST['morada'];
$num = $_POST['num'];
$mail = $_POST['mail'];
$dataI = $_POST['dataI'];
$dataF = $_POST['dataF'];
$ordeb = $_POST['ordeb'];
$orde = $_POST['orde'];
$notas1 = $_POST['notas1'];
$notas2 = $_POST['notas2'];
try
{
$db = new PDO('mysql:host=localhost;dbname=DBNAME;charset=utf8', 'USERNAME', 'PASSWORD');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$sql = "INSERT INTO Colaboradores (nomeF, nomeL, descP, morada, mail, ordeb, orde, dataI, dataF, notas1, notas2)
VALUES (:nomeF, :nomeL, :descP, :morada, :num, :mail, :ordeb, :orde, :dataI, :dataF, :notas1, :notas2)";
$stmt = $db->prepare($sql);
$stmt->bindValue('nomeF', $nomeF, PDO::PARAM_STR);
$stmt->bindValue('nomeL', $nomeL, PDO::PARAM_STR);
$stmt->bindValue('descP', $descP, PDO::PARAM_STR);
$stmt->bindValue('morada', $morada, PDO::PARAM_STR);
$stmt->bindValue('num', $num, PDO::PARAM_INT);
$stmt->bindValue('mail', $mail, PDO::PARAM_STR);
$stmt->bindValue('ordeb', $ordeb, PDO::PARAM_STR);
$stmt->bindValue('dataI', $dataI, PDO::PARAM_STR);
$stmt->bindValue('dataF', $dataF, PDO::PARAM_STR);
$stmt->bindValue('notas1', $notas1, PDO::PARAM_STR);
$stmt->bindValue('notas2', $notas2, PDO::PARAM_STR);
$stmt->execute();
EDIT
I build your project on my computer, try to add
$error = $stmt->errorInfo();
print_r($error);
To see what's happen during your request.
On my side, I found a mismatch with the word ordeb and ordb
For example : $stmt->bindValue('ordb', $ordeb, PDO::PARAM_INT);
And can you check also the format of your date, it should be "Y-m-d H:i:s")
Note : All your columns in your table are of text type, text should be used only for long text (like in textarea), you should use varchar which allow you to save up to 255 characters (enough).
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'];
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);
...
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();