Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 26th, 2013  |  syntax: None  |  size: 3.10 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Fatal error: Call to a member function getId() on a non-object in applications/XAMPP/xamppfiles/htdocs/CDStore/creditCardAccess.php on line 36
  2.        
  3. <?php
  4.  
  5. class creditCardAccess {
  6.  
  7. protected $link;
  8.  
  9. public function __construct() {
  10.     $host = "localhost";
  11.     $username = "root";
  12.     $password = "";
  13.     $database = "CDStore";
  14.  
  15.     $dsn = "mysql:host=$host;dbname=$database";
  16.  
  17.     $this->link = new PDO($dsn, $username, $password);
  18.     $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19. }
  20.  
  21. public function __destruct() {
  22.     $this->link = null;
  23. }
  24. public function insertCreditCard($creditCard) {
  25.     if (!isset($creditCard) && $creditCard != null) {
  26.         throw new Exception("Credit Card Required");
  27.     }
  28.  
  29.     $sql = "INSERT INTO creditCards(cardType, cardName, cardNumber, cardExpiryDate, cardCCV, userID)"
  30.             . "VALUES (:cardType, :cardName, :cardNumber, :cardExpiryDate, :cardCCV, :userID)";
  31.  
  32.     $params = array(
  33.         'cardType' => $creditCard->getCardType(),
  34.         'cardName' => $creditCard->getCardName(),
  35.         'cardNumber' => $creditCard->getCardNumber(),
  36.         'cardExpiryDate' => $creditCard->getCardExpiryDate(),
  37.         'cardCCV' => $creditCard->getCardCCV(),
  38.         'userID' => $user->getId()
  39.     );
  40.  
  41.     $stmt = $this->link->prepare($sql);
  42.     $status = $stmt->execute($params);
  43.     if ($status != true) {
  44.         $errorInfo = $stmt->errorInfo();
  45.         throw new Exception("Could Not Add Credit Card: " . $errorInfo[2]);
  46.     }
  47.  
  48.     $id = $this->link->lastInsertId('creditCard');
  49.     $creditCard->setId($id);
  50. }
  51.  
  52. }
  53. ?>
  54.        
  55. public function insertCreditCard($creditCard, $user) {
  56.        
  57. <?php
  58.  
  59. require_once("user.class.php"); //the user management class path
  60.  
  61. class creditCardAccess {
  62.  
  63. protected $link;
  64.  
  65. var $user;
  66.  
  67. public function __construct() {
  68.     $host = "localhost";
  69.     $username = "root";
  70.     $password = "";
  71.     $database = "CDStore";
  72.  
  73.     $dsn = "mysql:host=$host;dbname=$database";
  74.  
  75.     $this->link = new PDO($dsn, $username, $password);
  76.     $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  77.     $this->user = new User();
  78. }
  79.  
  80. public function __destruct() {
  81.     $this->link = null;
  82. }
  83. public function insertCreditCard($creditCard) {
  84.     if (!isset($creditCard) && $creditCard != null) {
  85.         throw new Exception("Credit Card Required");
  86.     }
  87.  
  88.     $sql = "INSERT INTO creditCards(cardType, cardName, cardNumber, cardExpiryDate, cardCCV, userID)"
  89.             . "VALUES (:cardType, :cardName, :cardNumber, :cardExpiryDate, :cardCCV, :userID)";
  90.  
  91.     $params = array(
  92.         'cardType' => $creditCard->getCardType(),
  93.         'cardName' => $creditCard->getCardName(),
  94.         'cardNumber' => $creditCard->getCardNumber(),
  95.         'cardExpiryDate' => $creditCard->getCardExpiryDate(),
  96.         'cardCCV' => $creditCard->getCardCCV(),
  97.         'userID' => $user->getId()
  98.     );
  99.  
  100.     $stmt = $this->link->prepare($sql);
  101.     $status = $stmt->execute($params);
  102.     if ($status != true) {
  103.         $errorInfo = $stmt->errorInfo();
  104.         throw new Exception("Could Not Add Credit Card: " . $errorInfo[2]);
  105.     }
  106.  
  107.     $id = $this->link->lastInsertId('creditCard');
  108.     $creditCard->setId($id);
  109. }
  110.  
  111. }
  112. ?>
clone this paste RAW Paste Data