0
$que=mysql_query("select col_name from tbl_column_selected") or 
die(mysql_error());
while(list($row_info) = mysql_fetch_array($que)) { 
  $data_arr[] = $row_info;
}  

for($i=0; $i < count($data_arr); $i++) {
  $col = $data_arr[$i];
  mysqli_query($con,"ALTER TABLE tbl_display_selected_column ADD ".$col." 
 CHAR(50)");
}
for($j=0; $j<count($data_arr); $j++) {
  $res = $data_arr[$j];
  mysqli_query($con,"ALTER TABLE tbl_display_selected_column DROP ".$res."");
}

I can add columns to the table but i cannot drop the columns created. I have checked the columns are empty but still cannot drop. please help with the code.

Viswanath Polaki
  • 1,357
  • 1
  • 10
  • 19
  • 2
    Please see [Why shouldn't I use mysql_* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Masivuye Cokile Jul 04 '17 at 12:52
  • this question needs more informations. For example: Do you get any kind of error message/exception? Does your user have permission to drop columns? Also what @MasivuyeCokile wrote. – Steffen Winkler Jul 04 '17 at 13:20

0 Answers0