Q:

PostgreSQL currval lastval functions returning a string not a number

I am trying to use the PostgreSQL currval function to retrieve a serial field which is automatically generated but I get a string instead of an int. My code is below    
$q ="insert into       contest(name,email,cam_b,cam_e,room_num,game,amount,phone_no)values('$name','$mail','$d','$dd','o','$game','$amount','$phone')";
$q1=pg_query($q)or die(pg_last_error());
$q5="select currval('contest_no_seq')";
$v=pg_query($q5)or die(pg_last_error());

$v returns Resource id #5 instead of an int value and i cant seem to use the strpos function to get the position of #
$er=strpos($v,'d');
if($er===false)
echo "not";
else
echo "$er -";

I am using PostgreSQL on Heroku.

A:

I don't understand what exactly is being returned but it is better to return the sequence value in the insert command:
$q = "
    insert into contest (
      name, email,cam_b, cam_e, room_num, game, amount, phone_no
    ) values (
    '$name','$mail','$d','$dd','o','$game','$amount','$phone'
    ) returning id
";

returning id above is the sequence column.

