这就是我的数据库表:
id | role | adviser
1 | section |
2 | teacher |
我想插入一个新部分,并使用顾问列更新现有教师。这可能吗?
答案 0 :(得分:1)
使用pdo,但已成功连接
require_once 'includes/db_connect.php';
因为你已经使用select获取值并将它们分配给变量$ sectionfromadviser和$ teacherfromadviser你可以像这样的程序
try{
//update the verify column from users
$sql="UPDATE tablename SET section=:section,teacher=:teacher WHERE id = :id";
$stmt= $db->prepare($sql);
$stmt->bindParam(':section', $sectionfromadviser);
$stmt->bindParam(':teacher', $teacherfromadviser);
$stmt->bindParam(':id', $id);
$stmt->execute();
}catch(PDOException $e){
if(!$stmt->execute()){
throw $e;
}
}catch (Exception $e) {
throw $e;
}