[英]php i can't insert into mysql database but no error
I'm trying to insert data to a MySQL database using PHP but it's not working.我正在尝试使用 PHP 将数据插入 MySQL 数据库,但它不起作用。
Before I add the code for insert, I checked if the POST is working and getting the data I need from the input.在添加插入代码之前,我检查了 POST 是否正常工作并从输入中获取我需要的数据。
This is the stored procedure这是存储过程
BEGIN
INSERT INTO students
(
signatoryid,
signatoryname,
signatoryposition,
signatoryoffice
)
VALUES
(
p_signatoryid,
p_signatoryname,
p_signatoryposition,
p_signatoryoffice
) ;
END
This is my php to insert data to MySQL.这是我将数据插入到 MySQL 的 php。 I'm receiving the successful alert but it's not inserting into the database.我收到成功的警报,但它没有插入到数据库中。
<?php
if (isset($_POST['submit'])){
$signatory_name = $_POST['sig_name'];
$signtory_position = $_POST['sig_position'];
$signatory_office = $_POST['sig_office'];
require_once 'dbconfig.php';
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname",$username, $password);
$stmt = $conn->prepare("CALL sp_insertsignatory (?), (?), (?), (?)");
$value = '0001';
$stmt->bindParam(1, $value, PDO::PARAM_STR, 10);
$stmt->bindParam(2, $signatory_name, PDO::PARAM_STR, 30);
$stmt->bindParam(3, $signtory_position, PDO::PARAM_STR, 30);
$stmt->bindParam(4, $signatory_office, PDO::PARAM_STR, 30);
$stmt->execute();
echo '<script language="javascript">';
echo 'alert("successful")';
echo '</script>';
} catch (PDOException $pe) {
die("Error occurred:" . $pe->getMessage());
}
}
?>
the problem is the table name i used in the stored procedure after fred ii pointed this website http://php.net/manual/en/pdo.error-handling.php and applying it to my code.问题是我在 fred ii 指向这个网站http://php.net/manual/en/pdo.error-handling.php并将其应用到我的代码之后在存储过程中使用的表名。 i receive the error and know what's the problem我收到错误并知道是什么问题
$conn = new PDO("mysql:host=$host;dbname=$dbname",$username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
$stmt = $conn->prepare("CALL sp_insertsignatory (?,?,?,?)");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.