-2

I already tried:-

$last_id = $stmt->lastInsertId();

But still its not returning string nor data, its just white blank page, any idea on how to return last id using PDO ?

PHP

public function createTrip($trip_name,$trip_cost,$trip_start,$trip_end,$trip_location,$trip_description)
{
    try
    {

        $stmt = $this->conn->prepare("INSERT INTO trips(trip_name,trip_cost,trip_start,trip_end,trip_location,trip_description) 
                                                   VALUES(:trip_name,:trip_cost,:trip_start,:trip_end,:trip_location,:trip_description)");

        $stmt->bindparam(":trip_name", $trip_name);
        $stmt->bindparam(":trip_cost", $trip_cost);
        $stmt->bindparam(":trip_start", $trip_start);
        $stmt->bindparam(":trip_end", $trip_end);
        $stmt->bindparam(":trip_location", $trip_location);
        $stmt->bindparam(":trip_description", $trip_description);

        $stmt->execute();   
        $last_id = $stmt->lastInsertId();

        return $stmt;   
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }               
}

HTML

 $trip = new TRIP();
 $trip>createTrip($trip_name,$trip_cost,$trip_start,$trip_end,$trip_location,$trip_description);
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Martney Acha
  • 2,802
  • 4
  • 33
  • 48

1 Answers1

0

Try this.

$last_id = $this->conn->lastInsertId();

return $last_id;

http://php.net/manual/en/pdo.lastinsertid.php

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45