Wednesday, 15 September 2010

mysql - PHP mysqli not adding column (ALTER TABLE) via a variable -



mysql - PHP mysqli not adding column (ALTER TABLE) via a variable -

i'm trying add together column table using next code. not letting me insert column name via variable ($document_type).

$document_type=$_post['document_type']; $category=$_post['category']; $file_extension=$_post['file_extension']; // database insert $sql_link = connect_mysqli_db(); $stmt1 = $sql_link->prepare("insert document_type (document_type,category,file_extension) values (?,?,?)"); $stmt1->bind_param('sss',$document_type,$category,$file_extension); if($stmt1->execute()){ //problem here $sql_link->query("alter table hr_types add together $document_type varchar(255) null"); }

if type column name statically works. variable noting happens, not error. tried can think of.

this should work. :)

$sql_link->query("alter table `hr_types` add together `{$document_type}` varchar(255) null");

php mysql mysqli

No comments:

Post a Comment