-1
$setEndedDate = ("UPDATE spaceships_list SET ended = :date WHERE id = :spaceship_id");
$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s'));
$setEndedDate->bindParam(":spaceship_id", $row["spaceship_id"]);
$setEnded->execute();
$endFlight = $db->prepare("DELETE FROM flights WHERE spaceship_id = :spaceship_id");
$endFlight->bindParam(":spaceship_id", $row["spaceship_id"]);
continue;

This returns error

Fatal error: Call to a member function bindParam() on a non-object

with the line reffering to the line number 2 shown.

$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s'));

Not sure why I'm getting the error.

user3271847
  • 35
  • 1
  • 7
  • Perhaps because you are calling a member function (method) on a non-object? Obviously, $db->prepare did not return an object. – Pavel S. Feb 23 '14 at 13:38
  • possible duplicate of [Fatal error: Call to a member function bindParam()](http://stackoverflow.com/questions/7941089/fatal-error-call-to-a-member-function-bindparam), or [this](http://stackoverflow.com/questions/4488035/call-to-a-member-function-bind-param-on-a-non-object), or [this](http://stackoverflow.com/questions/18921670/fatal-error-call-to-a-member-function-bind-param-on-a-non-object), or [this](http://stackoverflow.com/questions/18401682/call-to-a-member-function-bindparam-on-a-non-object) – Kermit Feb 23 '14 at 13:38
  • @PavelS. OP didn't even `prepare` on `$setEndedDate` – kero Feb 23 '14 at 13:38
  • Oh, shoot. I didn't use $db->prepare! Thanks! – user3271847 Feb 23 '14 at 13:39
  • 1
    `$setEndedDate` is string it is not an object. – Awlad Liton Feb 23 '14 at 13:41

1 Answers1

1

your $setEndedDate is string it should be an object.

your problem is here:

$setEndedDate = ("UPDATE spaceships_list SET ended = :date WHERE id = :spaceship_id");

$setEndedDate it should be an object like $endFlight. you have correct object for $endFlight but you do not have object for $setEndedDate.

try this:

$setEndedDate =  $db->prepare("UPDATE spaceships_list SET ended = :date WHERE id = :spaceship_id");
$setEndedDate->bindParam(":date", date_format($date, 'Y-m-d H:i:s'));
$setEndedDate->bindParam(":spaceship_id", $row["spaceship_id"]);
$setEnded->execute();
$endFlight = $db->prepare("DELETE FROM flights WHERE spaceship_id = :spaceship_id");
$endFlight->bindParam(":spaceship_id", $row["spaceship_id"]);
continue;
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53