Okay, so I am not entirely sure how to fix this. Im attempting to make a tag feature for my site but I am getting:
Fatal error: Call to a member function prepare() on a non-object in /Users/Home/Sites/functions/users.php on line 10
Here is the code that relates to this.
First is the connect file (connect.php)
<?php
mysql_connect('localhost','root','myphpadmin');
mysql_select_db('luminregister');
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "myphpadmin";
$dbname = "luminregister";
// connect using PDO
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch(PDOException $e) {
echo $e->getMessage();
die();
}
?>
The next file of merit is users.php which for this matter is
<?php
function register_tags($tags) {
$tagname = explode( ',', $tags );
foreach (range(1,count($tagname)) as $tagnumber) {
$bind[] = ':tag_name'.$tagnumber;
}
$sql = sprintf("INSERT INTO `question_tags` (tag_name) VALUES ( %s )", implode( '),(', $bind ));
$stmt = $dbh->prepare($sql);
foreach( $tagname as $k => $tag ) {
$stmt->bindValue( ":tag_name" . ++$k, $tag_name );
}
$stmt->execute();
}
?>
The idea is to take the tags from a single input separated by commas and then input them into sql inside independent columns (each labled tag_name1 through tag_name10). This is the only PDO that ive had issues with (my other cascading drops work just fine). Normally, my understandins is that the prepare() is not calling the pdo, but Im almost certain this one is just fine. So I could use some serious help here.
Another option, being that I completely missed the mark for the stated goal, would be alternative advice.
Thank you in advance for any assistance.