I've created a function to check if a record exists or not, but it gives me these errors:
Notice: Undefined variable: db in D:\wamp\www\Whq\admin_operation.php on line 31
Fatal error: Call to a member function query() on a non-object in D:\wamp\www\Whq\admin_operation.php on line 31
if($mode=='add_image')
{ $tags_array = array();
$tags = $_POST['tags'];
/*function to check tag exist or not */
function check_tag_exist($t)
{
$result = $db->query('select tag_name from whq_tags where tag_name like "'.$t.'" ');
$no=$result->num_rows;
if($no==0)
{
return true;
}
else
{
return false;
}
}
/* prepared stmnt created for whq_tags table */
if($stmt = $db->prepare('insert into whq_tags(tag_name) values (?)'))
{
$stmt -> bind_param('s', $tags_name);
foreach($tags as $tag1)
{
$tag1 = $tags_name;
if(check_tag_exist($tags_name))
{
$db->execute();
}
}
/* Close the statement */
$stmt->close();
}
else
{
/* Error */
printf("Prepared Statement Error: %s
", $db->error);
}
}
Variable $db inside check_tag_exist function is not working , while it working at other places. Please help me out. Thanks in advance.