PDO准备的声明更新不起作用

时间:2014-03-04 13:01:24

标签: php mysql sql pdo

是准备好的陈述和PDO的新手。我有一个带有两个预处理语句的脚本,insert语句工作正常,但更新没有。它不返回任何错误并显示成功消息,但它不会更新数据库。

这是不起作用的代码。任何帮助都会非常感激。感谢

$queryString="UPDATE team_directory SET team_name=':team_name',
aka=':aka',
website=':website',
main_contact=':main_contact',
phone=':phone',
email=':email',
other=':other',
np1=':np1',
np2=':np2',
np3=':np3',
np4=':np4',
np5=':np5',
np6=':np6',
np7=':np7',
np8=':np8',
np9=':np9',
np10=':np10',
np11=':np11',
np12=':np12'
where team_id=':team_id'";

$query=$database->prepare($queryString);
$query->execute(array(':team_name'=>$team_name,
':aka'=>$aka,
':website'=>$website,
':main_contact'=>$main_contact,
':phone'=>$phone,
':email'=>$email,
':other'=>$other,
':np1'=>$np1,
':np2'=>$np2,
':np3'=>$np3,
':np4'=>$np4,
':np5'=>$np5,
':np6'=>$np6,
':np7'=>$np7,
':np8'=>$np8,
':np9'=>$np9,
':np10'=>$np10,
':np11'=>$np11,
':np12'=>$np12,
':team_id'=>$team_id));

if ($query->errorCode()==0) {




    echo "<p>Team amended successfully, <a href=\"select_amend_team.php\">Amend Another</a>    </p>
    <p><a href=\"admin_team_directory.php\">Team Directory</a></p>
    <p><a href=\"admin_home.php\">Admin Homepage</a></p>";
}

else {
    $errors=$query->errorInfo();
    echo ($errors[2]);
}

1 个答案:

答案 0 :(得分:1)

简单地从这些邪恶的引号中取出占位符(您可以使用的准备好的变量语句标记):

$queryString="UPDATE team_directory SET team_name = :team_name,
  aka = :aka,
  website = :website,
  main_contact = :main_contact,
  phone = :phone,
  email = :email,
  other = :other,
  np1 = :np1,
  np2 = :np2,
  np3 = :np3,
  np4 = :np4,
  np5 = :np5,
  np6 = :np6,
  np7 = :np7,
  np8 = :np8,
  np9 = :np9,
  np10 = :np10,
  np11 = :np11,
  np12 = :np12
  where team_id = :team_id";