title: Getting an MySQL error using php
body: <p>I'm using a for loop to go through an array and trying to make that the fields name in my database in phpmyadmin. The table gets created but my field name does not. Is there a reason for this?</p>
  
  <p>At first I thought it was because of the space in each array so I replaced it with "_". </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  include 'simple_html_dom.php';
  include ('connection.php');
  
  
  function getsquad($url, $tablename){
  
  $html = file_get_html($url);
  
  $player_fromsite = array();
  
  $space = ' ';
  $replacespace = '_';
  
  $player = array();
  
  foreach($html-&gt;find('td[align=left]') as $element) {
     if ($element-&gt;children(0)) { // work only when children exists
            array_push($player_fromsite ,$element-&gt;children(0)-&gt;innertext);
     }
  }
  
  array_push($player, str_ireplace($space, $replacespace, $player_fromsite));
  unset($player_fromsite);
  
  $length = count($player);
  
  for($i = 0;$i&lt;=$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-&gt;getsquad('site', 'Ars');
  
  ?&gt;
  </code></pre>
  
  <p>The error message I'm getting are:
  "Array to string conversion"
  "Undefined offset: 1"</p>
  
  <p>"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 'VARCHAR(30) )' at line 2"</p>
  
  <p>The errors are all on one line "$player[$i] VARCHAR(30) ) ") or die(mysql_error());"</p>