Jump to content



Photo

need a PHP error check!?


  • Please log in to reply
5 replies to this topic

#1 Original Poster

Original Poster

    Systems Developer

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7/8, Kali, ubuntu, OSx 10.9
  • Phone: Android

Posted 24 March 2013 - 20:00

below is my code... its being called from another function I am getting this error


FATAL ERROR: Call to a member function prepare() on a non-object

can anyone spot my mistake?? thanks for help
public function newPData($AL1, $AL2, $town, $county, $phone, $ID)
{


$ig = $this->PDO->prepare("INSERT INTO `PD`(`AL1`, `AL2`, `TOWN`, `COUNTY`, `ID`, `PHONE`)VALUES(:AL1, :AL2, :TOWN, :COUNTY, :ID, :PHONE)");
$ig->execute(array( ':AL1' =>     $AL1,
':AL2' =>     $AL2,
':TOWN' =>    $town,
':COUNTY' =>  $county,
':ID' =>      $ID,
':PHONE' =>   $phone
));

}



#2 Niekess

Niekess

    Windows Platform Developer

  • Joined: 12-September 11
  • Location: The Netherlands
  • OS: Windows 8.1 Update 1
  • Phone: Nokia Lumia 930

Posted 24 March 2013 - 20:16

Are you sure the "PDO" is a database object? The error kind of says it isn't.

#3 OP Original Poster

Original Poster

    Systems Developer

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7/8, Kali, ubuntu, OSx 10.9
  • Phone: Android

Posted 24 March 2013 - 20:19

Are you sure the "PDO" is a database object? The error kind of says it isn't.


yes 100% sure all my other code works but this

#4 virtorio

virtorio

    Neowinian Senior

  • Tech Issues Solved: 14
  • Joined: 28-April 03
  • Location: New Zealand
  • OS: OSX 10.10, Windows 8.1
  • Phone: LG G3

Posted 24 March 2013 - 20:21

You'd only get that error if PDO hasn't been initialised or is set to a non-object type.

Run this code and paste the output here:
var_dump($this->PDO);


#5 The_Decryptor

The_Decryptor

    STEAL THE DECLARATION OF INDEPENDENCE

  • Tech Issues Solved: 5
  • Joined: 28-September 02
  • Location: Sol System
  • OS: iSymbian 9.2 SP24.8 Mars Bar

Posted 24 March 2013 - 20:24

Personally I'd put the prepare statement next to where you initialize the PDO connection, so it isn't created/destroyed every time the function is run, and it'd also negate any scoping issues, etc.

#6 OP Original Poster

Original Poster

    Systems Developer

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7/8, Kali, ubuntu, OSx 10.9
  • Phone: Android

Posted 24 March 2013 - 20:27

dont worry got it sorted I was calling a new bject within the class where an object had originally been created in order to call the new object :p ... just had to put in "$this->"