0
 <?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()));
      } ?>
2
  • 3
    Please format the code Commented Dec 30, 2013 at 7:50
  • @user3144122 , why do you revert the formatting edit ? Commented Dec 30, 2013 at 8:07

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

Comments

-1

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()));
    }
}

4 Comments

sir my second code not work properly where data insert into data base
@user3144122 : First try it. If not worked then tell me the output of var_dump($value);
thank you sir its working thank you for your kind help for your valuable time....
@user3144122 : If it worked please Click the tick (check mark) on left under the vote arrows.It will be a green mark if it is accepted correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.