Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fatal error: Call to a member function getId() on a non-object in applications/XAMPP/xamppfiles/htdocs/CDStore/creditCardAccess.php on line 36
- <?php
- class creditCardAccess {
- protected $link;
- public function __construct() {
- $host = "localhost";
- $username = "root";
- $password = "";
- $database = "CDStore";
- $dsn = "mysql:host=$host;dbname=$database";
- $this->link = new PDO($dsn, $username, $password);
- $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- public function __destruct() {
- $this->link = null;
- }
- public function insertCreditCard($creditCard) {
- if (!isset($creditCard) && $creditCard != null) {
- throw new Exception("Credit Card Required");
- }
- $sql = "INSERT INTO creditCards(cardType, cardName, cardNumber, cardExpiryDate, cardCCV, userID)"
- . "VALUES (:cardType, :cardName, :cardNumber, :cardExpiryDate, :cardCCV, :userID)";
- $params = array(
- 'cardType' => $creditCard->getCardType(),
- 'cardName' => $creditCard->getCardName(),
- 'cardNumber' => $creditCard->getCardNumber(),
- 'cardExpiryDate' => $creditCard->getCardExpiryDate(),
- 'cardCCV' => $creditCard->getCardCCV(),
- 'userID' => $user->getId()
- );
- $stmt = $this->link->prepare($sql);
- $status = $stmt->execute($params);
- if ($status != true) {
- $errorInfo = $stmt->errorInfo();
- throw new Exception("Could Not Add Credit Card: " . $errorInfo[2]);
- }
- $id = $this->link->lastInsertId('creditCard');
- $creditCard->setId($id);
- }
- }
- ?>
- public function insertCreditCard($creditCard, $user) {
- <?php
- require_once("user.class.php"); //the user management class path
- class creditCardAccess {
- protected $link;
- var $user;
- public function __construct() {
- $host = "localhost";
- $username = "root";
- $password = "";
- $database = "CDStore";
- $dsn = "mysql:host=$host;dbname=$database";
- $this->link = new PDO($dsn, $username, $password);
- $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->user = new User();
- }
- public function __destruct() {
- $this->link = null;
- }
- public function insertCreditCard($creditCard) {
- if (!isset($creditCard) && $creditCard != null) {
- throw new Exception("Credit Card Required");
- }
- $sql = "INSERT INTO creditCards(cardType, cardName, cardNumber, cardExpiryDate, cardCCV, userID)"
- . "VALUES (:cardType, :cardName, :cardNumber, :cardExpiryDate, :cardCCV, :userID)";
- $params = array(
- 'cardType' => $creditCard->getCardType(),
- 'cardName' => $creditCard->getCardName(),
- 'cardNumber' => $creditCard->getCardNumber(),
- 'cardExpiryDate' => $creditCard->getCardExpiryDate(),
- 'cardCCV' => $creditCard->getCardCCV(),
- 'userID' => $user->getId()
- );
- $stmt = $this->link->prepare($sql);
- $status = $stmt->execute($params);
- if ($status != true) {
- $errorInfo = $stmt->errorInfo();
- throw new Exception("Could Not Add Credit Card: " . $errorInfo[2]);
- }
- $id = $this->link->lastInsertId('creditCard');
- $creditCard->setId($id);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement