<?php
$month=$_SESSION['month'];
$colname=$_SESSION['colname'];
require('connect.php');
global $pdo;
$stmt=$pdo->prepare('SHOW COLUMNS FROM `selections` LIKE ":s%"');
$stmt=bindParam(':s',$colname);$stmt->execute();$row =$stmt->fetch()?true:false;
if($row==false){$sql=$pdo->prepare("ALTER TABLE `$month` ADD `$colname` VARCHAR( 120)NOT NULL DEFAULT 'absent'");
$sql->execute();}else{die("error".print_r($sql>errorinfo()));
}
?>
代码错误调用未定义的函数bindParam(); 绑定(bind)错误 这里 $month 是用户动态选择的月份,$colname 也是用户选择的
<?php
$month=$_SESSION['month'];
$colname=$_SESSION['colname'];
$tot='present';
require('connect.php');
global $pdo;
$stmt=$pdo->prepare("UPDATE `$month` SET `$colname`=:a WHERE roll =:foo");
$stmt=bindparam(':a',$tot);
foreach( $value as $value)
{
$stmt>bindParam(':foo',$value);
$stmt->execute();
}
if($stmt==false)
{
die("error".print_r($stmt->errorinfo()));
} ?>
最佳答案
错误1
你的意思可能是:
$stmt->bindParam(':s',$colname);
错误2
此外,您尚未通过 session_start()
启动 session
错误3
应该是:
die("error".print_r($sql->errorinfo(), true));
错误4
您可能想要:
$stmt->bindParam(':foo',$value);
而不是:
$stmt>bindParam(':foo',$value);
顺便说一句,您更喜欢用单行编写代码?
关于php - pdo 查询更改表其中列名不存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835492/