PDO在MySQL中插入重复数据

时间:2016-02-09 02:25:09

标签: php mysql pdo

我有以下代码,每当调用该函数时,它都会插入两次数据。

调用类/函数的php:

$add_amenity = new listing;
echo $add_amenity->add_amenity($_POST['name']);

这是功能:

    public function add_amenity($a)
{
        try {
            $dbh = new PDO("mysql:host=" . db_host . ";dbname=" . db_name . "",db_user,db_password);
            $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

            $q = $dbh->prepare("INSERT INTO amenitylist (id,name,icon,isactive) VALUES ('',:a,'','1')");
            $q->bindParam(':a', $a);
            $q->execute();
            $this->_results = $dbh->lastInsertId();
        } catch(PDOException $e) {
            $this->_results = "ERROR: " . $e->getMessage();
        }
}

0 个答案:

没有答案