0

このコードを使用すると、DB レコードをテーブルで表示できます。このテーブルには、レコードを削除または編集するオプションがあります。このエラー メッセージが表示されるのは私だけで、何が間違っているのかわかりません。

エラーメッセージ:

致命的なエラー: 32 行目の C:\wamp\www\Inventaris++\NinjaCodeDelete.php の非オブジェクトに対するメンバー関数 prepare() の呼び出し

コード:

<?php
include'Connect2db3.php';

$action = isset($_GET['action']) ? $_GET['action']: "";

if($action=='delete'){ //if the user clicked ok, run our delete query
    try {

        $query = "DELETE FROM BCD WHERE id = ?";
        $stmt = $conn->prepare($query);
        $stmt->bindParam(1, $_GET['id']);

        $result = $stmt->execute();
        echo "<div>Record was deleted.</div>";

    }catch(PDOException $exception){ //to handle error
        echo "Error: " . $exception->getMessage();
    }

}

$query = "SELECT ID, Categorie, SerieNummer, MacAdress, ProductCode, Prijs, RekNummer, PaletNummer, Hoeveelheid, Aantekeningen FROM BCD";
$stmt = $conn->prepare( $query );
$stmt->execute();

$num = $stmt->rowCount();

echo "<a href='reports.php'>View Reports</a>";

if($num>0){ //check if more than 0 record found

    echo "<table border='1'>";//start table

        echo "<tr>";
            echo "<th>Categorie</th>";
            echo "<th>SerieNummer</th>";
            echo "<th>MacAdress</th>";
            echo "<th>ProductCode</th>";
            echo "<th>Prijs</th>";
            echo "<th>RekNummer</th>";
            echo "<th>PaletNummer</th>";
            echo "<th>Hoeveelheid</th>";
            echo "<th>Aantekeningen</th>";
        echo "</tr>";

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

            extract($row);

            echo "<tr>";
                echo "<td>{$Categorie}</td>";
                echo "<td>{$SerieNummer}</td>";
                echo "<td>{$MacAdress}</td>";
                echo "<td>{$ProductCode}</td>";
                echo "<td>{$Prijs}</td>";
                echo "<td>{$RekNummer}</td>";
                echo "<td>{$PaletNummer}</td>";
                echo "<td>{$Hoeveelheid}</td>";
                echo "<td>{$Aantekeningen}</td>";
                echo "<td>";

                    echo "<a href='edit.php?id={$id}'>Edit</a>";
                    echo " / ";

                    echo "<a href='#' onclick='delete_user( {$id} );'>Delete</a>";
                echo "</td>";
            echo "</tr>";
        }

    echo "</table>";//end table

}else{ 
    echo "No records found.";
}

?>

<script type='text/javascript'>

    function delete_user( id ){
        var answer = confirm('Are you sure?');
        if ( answer ){ 
            window.location = 'NinjaCodeDelete.php?action=delete&id=' + id;
        }
    }
</script>

また、私は高度なプログラマーではないと言いたいのですが、このコードをオンラインで見つけたところ、それを使用した他の人のために機能しているように見えました。Mysql と php の経験はありますが、PDO の経験はありません。あなたが私を助けてくれることを願っています!よろしくお願いします。

4

1 に答える 1