Reputation: 3
<?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()));
}
?>
code error Call to undefined function bindParam(); bindparm error here $month is month select dynamically by user and $colname is also select by user
<?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()));
} ?>
Upvotes: 0
Views: 1576
Reputation: 9351
try this:
session_start();
$month=$_SESSION['month'];
$colname=$_SESSION['colname'];
require('connect.php');
global $pdo;
$stmt=$pdo->prepare('SHOW COLUMNS FROM `selections` LIKE :s');
$query->bindValue(":s", $stmt);
$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()));
}
For second ERROR:
$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);
//I don't know what are in the $value
foreach( $value as $v){
$stmt->bindParam(':foo',$v);
if( !$stmt->execute())
{
die("error".print_r($stmt->errorinfo()));
}
}
Upvotes: -1
Reputation: 54212
Error 1
You probably mean :
$stmt->bindParam(':s',$colname);
Error 2
Also, you haven't started your session by session_start()
Error 3
It should be:
die("error".print_r($sql->errorinfo(), true));
Error 4
You may want:
$stmt->bindParam(':foo',$value);
instead of:
$stmt>bindParam(':foo',$value);
by the way, you prefer to write codes in single line?
Upvotes: 2