title: How do i create MySQL tables with php using HTML forms?
body: <p>I am interested in creating MySQL tables in PHP using HTML forms.An ideal example would be;
  1. A html form is presented where i enter table name and names of the fields that the table will have for example id,firstname,lastname and email.
  2.On submitting the form, the table should be added to the back end database with its respective fields. I have the following code.</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbname = "book";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $tablename = $_POST['MyGuests'];
  $id = $_POST['id'];
  $firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $email = $_POST['email'];
  
  
  // sql to create table
  $sql = "CREATE TABLE My (
  
  id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
  MyGuests VARCHAR(30) NOT NULL,
  firstname VARCHAR(30) NOT NULL,
  lastname VARCHAR(30) NOT NULL,
  email VARCHAR(50)
  )";
  
  if ($conn-&gt;query($sql) === TRUE) {
      echo "Table MyGuests created successfully";
  } else {
      echo "Error creating table: " . $conn-&gt;error;
  }
  
  $conn-&gt;close();
  ?&gt;
  
  
    &lt;form name="form1" method="post" action="mark.php" enctype="multipart/form-data"&gt;
    &lt;table width="80%" border="0" cellpadding="3" cellspacing="3"&gt;
     &lt;tr&gt;
      &lt;td&gt;ID&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" name="id" id="id"&gt;&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;Table name&lt;/td&gt;
       &lt;td&gt;&lt;input type="text" name="MyGuests" id="MyGuests"&gt;&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
      &lt;td&gt;First name&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="firstname" id="firstname"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;Last name&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" name="lastname" id="lastname"&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
     &lt;td&gt;Email&lt;/td&gt;
     &lt;td&gt;&lt;input type="text" name="email" id="email"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td&gt;&amp;nbsp;&lt;/td&gt;
     &lt;td&gt;&lt;input type="submit" name="Submit" id="Submit" value="Save Table"&gt;
     &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The problem i have is whenever i run the script, a MySQL table is created automatically.Attempting to create the table using the form doesn't seem to work.What am i doing wrong ?</p>