2

最初のステートメントがテーブルに挿入した後、テーブルから最後のrecord_idを取得しようとしています。最後のIDを表示するためのコードを印刷しているように見えますか?

      SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))";

コードはこちら

  else {
        echo 'Record added';
        $sql = "INSERT INTO sheet_tbl (site_id,  eventdate, eventtime, username, additionalvolunteers) VALUES ('$_POST[site_id]','$_POST[eventdate]','$_POST[eventtime]', '$username','$_POST[additionalvolunteers]')";

        echo $sql; //Just so I can see what is getting sent
        $result = pg_query($sql);

        $sheet_id_pull = "SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))";
        echo $sheet_id_pull; //This is where im having the issue with the above line.
}
4

1 に答える 1

2

多分

echo pg_query($sheet_id_pull);

それ以外の

echo $sheet_id_pull;

または

$sheet_id_pull = pg_query("SELECT CURRVAL (pg_get_serial_sequence('sheet_tbl','sheet_id'))");
echo $sheet_id_pull;

this質問も読んでください。挿入されたIDを取得するより良い方法があります。

于 2013-07-26T08:49:44.717 に答える