如何在数据库中插入列的新名称

There is a slight problem when I'm creating a new table in phpmyadmin with new field names. I'm using a for loop trying to insert data for the field names. But for some reason I'm getting a error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[0] VARCHAR(30)' at line 3".

Here is my code:

include 'simple_html_dom.php';
include ('connection.php');


function getsquad($url, $tablename){

$html = file_get_html($url);

$player = array();

foreach($html->find('td[align=left]') as $element) {
   if ($element->children(0)) { // work only when children exists
          array_push($player ,$element->children(0)->innertext);
   }
}

$length = count($player);

for($i = 0;$i<=$length;$i++){
// Create a MySQL table in the selected database
mysql_query("CREATE TABLE $tablename(

player[$i] VARCHAR(30)")
or die(mysql_error());  
}

echo "Table Created!";

}

$Squad = new squad();
$Squad->getsquad('site', 'Players'); 

?>

I know the first part of my function is working so I don't think it is a PHP error but not 100% sure.

You forgot the $ before player. The right way is:

mysql_query("CREATE TABLE $tablename($player[$i] VARCHAR(30)") or die(mysql_error());

update: And as user876345 said, you forget to close the parentheses. So, the code should be:

mysql_query(" CREATE TABLE $tablename( $player[$i] VARCHAR(30) ) ") or die(mysql_error());

You have missed to close the ) at the end of the query and also missed $ in player variable

CREATE TABLE $tablename( $player[$i] VARCHAR(30) )

Your code should be like:

 mysql_query("CREATE TABLE $tablename($player[$i] VARCHAR(30)") or die(mysql_error());