tags:

views:

66

answers:

1

Okay so here is the code that I am using

    function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto)
    {

        try {
            $stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)");
            if(!$stmt){
                $err = $this->pdo->errorInfo();
                throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]);
            }
            $stmt->bindValue(':title', $this->title, PDO::PARAM_STR);
            $stmt->bindValue(':description', $this->description, PDO::PARAM_STR);
            $stmt->bindValue(':price', $this->price, PDO::PARAM_INT);
            $stmt->bindValue(':qty', $this->qty, PDO::PARAM_INT);
            $stmt->bindValue(':photo', $this->photo, PDO::PARAM_STR);
            $stmt->execute();
        }catch (PDOException $e) {
            echo $e->getMessage();
        }


    }

$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg');

The database class and database call function work. Also if you spot anything retarded please point it out, I am trying to learn.

+2  A: 

Why $this->photo? Do you really have this property in your class? Or maybe you need something like this?

function AddProducts($aTitle, $aDescription, $aPrice, $aQty, $aPhoto)
{

    try {
        $stmt = $this->pdo->prepare("INSERT INTO products(title, price, description, qty, photo) VALUES(:title, :price, :description, :qty, :photo)");
        if(!$stmt){
            $err = $this->pdo->errorInfo();
            throw new RuntimeException('PRODUCT INSERT FAILED: '.$err[2]);
        }
        $stmt->bindValue(':title', $aTitle, PDO::PARAM_STR);
        $stmt->bindValue(':description', $aDescription, PDO::PARAM_STR);
        $stmt->bindValue(':price', $aPrice, PDO::PARAM_INT);
        $stmt->bindValue(':qty', $aQty, PDO::PARAM_INT);
        $stmt->bindValue(':photo', $aPhoto, PDO::PARAM_STR);
        $stmt->execute();
    }catch (PDOException $e) {
        echo $e->getMessage();
    }


}

$addProducts = $database->AddProducts('Ford Mustang', 'This is a Descriptiom', 299.99, 1, 'images/includes/5.jpg');
silent
+1 noticed the same, seems logical.
DrColossos
Thank you so much, that was perfect. Sorry still learning.
thatmediaguy