1

私はテーブルを持っています

percentile      int(3)  No           
FoSW            int(3)  Yes     NULL     
dfLR            int(3)  Yes     NULL     
FoA             int(3)  Yes     NULL     
SoG             int(3)  Yes     NULL     
RST             int(3)  Yes     NULL     
SSW             int(3)  Yes     NULL    
total           int(3)  No  

そして配列:

Array
(
    [percentile] => 99
    [FoSW] => 125
    [DfLR] => 110
    [FoA] => 60
    [SoG] => 120
    [RST] => 40
    [SSW] => 45
    [total] => 500
)

そして、何らかの理由で機能しないこのコード... Catch はエラーをスローしません。エラーをエコーするちょうど私のifステートメント...

if ($_POST['percent']=='add'){
    try{
        $post = $_POST;
        unset($post['percent']);

        $sth = $dbh->prepare("INSERT INTO percentiles (percentile, FoSW, dfLR, FoA, SoG, RST, SSW, total) VALUES (?,?,?,?,?,?,?,?)");

        if ($sth->execute($post)){
            echo 'done<br/>';
        }

        else echo 'error';
    }

    catch(PDOException $e){
        echo 'error'.$e;
    }
}
4

1 に答える 1

1

配列は操作に$post必要な 8 つの値と一致しますINSERTが、配列は連想配列/辞書ではなく整数でインデックス付けする必要があります。

Array
(
    [percentile] => 99
    [FoSW] => 125
    [DfLR] => 110
    [FoA] => 60
    [SoG] => 120
    [RST] => 40
    [SSW] => 45
    [total] => 500
)

上記の配列は、prepare()呼び出しを次のように変更すると機能します。

$sth = $dbh->prepare("INSERT INTO percentiles 
        (percentile, FoSW, 
        dfLR, FoA, 
        SoG, RST, 
        SSW, total) 
    VALUES
        (:percentile, :FoSW, 
        :DfLR, :FoA, 
        :SoG, :RST, 
        :SSW, :total)");
于 2013-07-17T21:00:06.273 に答える