I'm messing with PDO and I'm trying to insert some data into my table; however, I'm getting a DBConnect::prepare()
error.
Here's my insertcard.php file:
<?php
require_once "connection.php";
$Name = $_POST['cardname'];
$Colour = $_POST['colour'];
$Rarity = $_POST['rarity'];
$CardQuery = "INSERT INTO `cards`(`Name`, `Colour`, `Rarity`) VALUES (`:Name`,`:Colour`,`:Rarity`)";
$CardResult = $dbconnection->prepare($CardQuery);
$CardExec = $CardResult->execute(array(":Name"=>$Name,":Colour"=>$Colour,":Rarity"=>$Rarity));
if ($CardExec) {
Echo "Data Inserted!";
}
?>
And my function in connection.php that connects to my database:
private function Connect() {
try {
$db = $this->Connection = new PDO('mysql:host=' . $this->hostname . ';dbname=' . $this->dbname . '', $this->username, $this->password);
}
catch(PDOException $e)
{
echo $e->getMessage();
echo "<br>Wow, we done goofed.";
}
}
And instantiated by:
$dbconnection = new DBConnect('localhost', 'root', '', 'cardtest');
Does anyone know what the issue is? I'll show more of the connection.php file if need be.