简体   繁体   中英

Error 1366 on Calling a stored procedure (php mysql)

I'm writing a sript for let the users of my site to change some basic information stored in the db.

I wrote a stored procedure for it and I want to call it with a php script. When I do that I got this error:

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'Domenico' for column 'Cod_Utente' at row 1 in C:\\inetpub\\Portale\\php\\update_user.php:37 Stack trace: #0 C:\\inetpub\\Portale\\php\\update_user.php(37): PDOStatement->execute() #1 {main} thrown in C:\\inetpub\\Portale_ETS\\php\\update_user.php on line 37

Cod_Utente is the primary key of the table, integer, auto increment. Can u help me to find the problem pls? Here the code:

CREATE DEFINER=`root`@`localhost` PROCEDURE `update_user`(
IN v_Nome_UT VARCHAR(25),
IN v_Cog_UT VARCHAR(25),
IN v_Data_Iscrizione VARCHAR(45), 
IN v_Mail_UT VARCHAR(45),
IN v_Tel_UT VARCHAR(45),
IN Cod_Utente int

 )
BEGIN


update tab01_utenti
set 

Nome_UT=v_Nome_UT,
Cog_UT=v_Cog_UT,
Data_Iscrizione=v_Data_Iscrizione,
Mail_UT=v_Mail_UT,
Tel_UT=v_Tel_UT

where 
Cod_Utente=v_Cod_Utente;


commit;

END

Php script(The db connection is omitted but ok) :

$a = $_POST["nome"];
$b = $_POST["cognome"];
$c = $_POST["mail"];
$d = $_POST["data"];     
$e = $_POST["tel"];
$f = $_SESSION['Cod_Utente'];



// execute the stored procedure
$sql  = "CALL update_user(:v_Nome_UT, :v_Cog_UT, :v_Mail_UT, 
                          :v_Data_Iscrizione, :v_Tel_UT, :v_Cod_Utente)";
$stmt = $conn->prepare($sql);

$stmt->bindParam(':v_Nome_UT', $a, PDO::PARAM_STR);
$stmt->bindParam(':v_Cog_UT', $b, PDO::PARAM_STR);  
$stmt->bindParam(':v_Data_Iscrizione', $d, PDO::PARAM_STR);
$stmt->bindParam(':v_Mail_UT', $c, PDO::PARAM_STR);
$stmt->bindParam(':v_Tel_UT', $e, PDO::PARAM_STR);
$stmt->bindParam(':v_Cod_Utente', $f, PDO::PARAM_INT);
$stmt->execute();

You are storing a string value on $_SESSION['Cod_Utente'] , make sure the value is a valid integer before pass it to stored procedure.

$f = $_SESSION['Cod_Utente'];

The error says you have the text 'Domenico' instead of an integer value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM