簡體   English   中英

php我無法插入mysql數據庫但沒有錯誤

[英]php i can't insert into mysql database but no error

我正在嘗試使用 PHP 將數據插入 MySQL 數據庫,但它不起作用。

在添加插入代碼之前,我檢查了 POST 是否正常工作並從輸入中獲取我需要的數據。

這是存儲過程

BEGIN 

    INSERT INTO students
         (
           signatoryid, 
           signatoryname, 
           signatoryposition, 
           signatoryoffice                       

         )
    VALUES 
         ( 
           p_signatoryid, 
           p_signatoryname, 
           p_signatoryposition, 
           p_signatoryoffice                
         ) ; 
END

這是我將數據插入到 MySQL 的 php。 我收到成功的警報,但它沒有插入到數據庫中。

<?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());
    }   
}
?>

問題是我在 fred ii 指向這個網站http://php.net/manual/en/pdo.error-handling.php並將其應用到我的代碼之后在存儲過程中使用的表名。 我收到錯誤並知道是什么問題

$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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM