Hey there,
I am trying to work with inserting data into a database, when i go to insert it i receive “Fatal error: Call to a member function prepare() on a non-object” so that means that the pdo variable is not working right? In this case i am using $pdo for the pdo initiation in the connect.php file
(var’s defined)
try{
$pdo = new PDO('mysql:host='.$host.';dbname='.$database, $user,$pass);
}
catch(PDOExexption $e){
echo "<div class=\\"dbError\\">\
<p>There was an error connecting to the database: ".$e->getMessage()."</p>\
</div>";
}
and insert/check then insert query
public function add()
{
$query['1'] = 'SELECT COUNT(*) FROM users WHERE email = :email';
$values['1'] = array('email' => $this->email);
$check = $pdo->prepare($query['1']);
if($res = $check->execute($vlaues['1']))
{
if($check->fetchColumn() < 1)
{
$query['2'] = 'INSERT INTO users SET
email = :email,
password = :password,
dateJoined = CURDATE(),
farmName = :farmName,
name = :name,
salt1 = :salt1,
salt2 = :salt2,
limt_results = `15`,
level = `2`,
reciveEmail = :recive';
$values['2'] = array('email' => $this->email, 'password' => $this->password, 'farmname' => $this->farmname, 'name' => $this->farm, 'salt1' => $salt['2'], 'salt2' => $salt['1'], 'reciveEmail' => $this->reciveEmail );
$insert = $pdo->prepare($query['2']);
$insert->execute($values['2']);
$message = "Hello {$this->name}, \
your account has been created! you can login with {$this->email} and your correct password";
mail($this->email,'no-reply@ageasy.ca','Your New Account!',$message,'support@ageasy.ca');
}
do you see anything i am missing?
Thanks!
-Colin