我的脚本有问题。 我收到此错误:致命错误:无法访问空属性
代码是:
public function insertap()
{
try
{
//echo $_POST['tranzactie'].$_POST['tip'].$_POST['tip_loc'].$_SESSION['uid'];
$stmt=$this->$dbh->beginTransaction();
$sql="INSERT INTO `anunturi` (`tranzactie`, `tip`, `tip2`, `user`) VALUES (:tranz, :tip, :tip_loc, :user)" ;
$stmt->prepare($sql);
$data = array('tranz' => $_POST['tranzactie'], 'tip' => $_POST['tip'], 'tip_loc'=>$_POST['tip_loc'], 'user'=>$_SESSION['uid']);
$stmt->execute($data);
$stmt->commit();
}
catch (Exception $e)
{
$stmt->rollback();
echo "A aparut o eroare";
}
}
提前致谢...
答案 0 :(得分:0)
更改
$data = array('tranz' => $_POST['tranzactie'], 'tip' => $_POST['tip'], 'tip_loc'=>$_POST['tip_loc'], 'user'=>$_SESSION['uid']);
到
$data = array(':tranz' => $_POST['tranzactie'], ':tip' => $_POST['tip'], ':tip_loc'=>$_POST['tip_loc'], ':user'=>$_SESSION['uid']);
答案 1 :(得分:0)
-
$stmt=$this->$dbh->beginTransaction();
应该是
之类的东西$this->dbh->beginTransaction();
$sql = ...
$stmt = $this->dbh->prepare($sql);
用插入查询替换....