Tom
Tom

Reputation: 654

SELECT CURRVAL (pg_get_serial_sequence Im doing something wrong?

What am I doing wrong, I am trying to get the last record_id from a table, after the first statement inserts it into my table. I seem to just print the code that is meant to display the last id?

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

Code here

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

Upvotes: 1

Views: 8911

Answers (1)

Ihor Romanchenko
Ihor Romanchenko

Reputation: 28541

Maybe

echo pg_query($sheet_id_pull);

Instead of

echo $sheet_id_pull;

Or

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

Also read this question. It has a better way of getting the inserted id.

Upvotes: 2

Related Questions