Results 1 to 3 of 3

Thread: Create New Table

  1. #1
    Join Date
    Jun 2009
    Posts
    62
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Create New Table

    So I have a Form:
    HTML Code:
    <form action="createtable.php" method="post"
    Table Name: <input type="text" name="table"><br>
    <input type="submit" name="submit" value="submit">
    </form>
    I want this to create a table in my MySQL database. Possible?
    I have googled and come up with nothing.

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default

    Yup, it's possible to create a table through php script... try this:

    Code:
    <html>
    <head>
       <title></title>
    </head>
    
    <body>
    
      <form action="" method="post">
            Table Name: <input type="text" name="table"><br>
            <input type="submit" name="submit" value="submit">
      </form>
    </body>
    </html>
    
    <?php
    
      $con = mysql_connect("localhost","root","") or die(mysql_error());
      mysql_select_db("db",$con) or die(mysql_error());
    
      $tname = $_POST[table];
    
    
      // Creating a table with an attributes: ID and name
      $data = "Create table ". $tname . "(ID int, name varchar(30))";
      $query = mysql_query($data);
     
      if($query)
        echo "New table is created";
      mysql_close($con);
     
    ?>

  3. #3
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default

    you can try this website: www.w3schools.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •