4 Replies Latest reply on Jan 31, 2009 11:35 AM by ArizonaJohn

    Naming a MySQL table

    ArizonaJohn Level 1
      Hello,

      How do I name a MySQL table with a variable from an HTML form?

      I have attached the code I have so far to this message.

      Thanks,

      John
        • 1. Re: Naming a MySQL table
          jon@cmiwebstudio Level 3
          using a gui to work with mysql will make your life a little easier. MySQL has free tools you can download, or Navicat is an excellent software as well.
          • 2. Re: Naming a MySQL table
            Level 7
            ArizonaJohn wrote:
            > How do I name a MySQL table with a variable from an HTML form?

            It's not a very good idea, because you have no idea whether the value
            entered in the form is a legal table name, or even if it already exists.
            However, the code you have won't work because of syntax errors.

            If you really want to go ahead, try this:

            <?php
            if (isset($_POST['name']) && !empty($_POST['name'])) {
            mysql_connect("hostaddress", "username", "password") or
            die(mysql_error());
            mysql_select_db("sand2") or die(mysql_error());

            $table = mysql_real_escape_string($_POST['name']);

            $query = "CREATE TABLE `$table` (site VARCHAR(50))";
            $result = mysql_query($query) or die(mysql_error());
            }

            ?>


            --
            David Powers, Adobe Community Expert
            Author, "The Essential Guide to Dreamweaver CS4",
            "PHP Solutions" & "PHP Object-Oriented Solutions"
            http://foundationphp.com/
            • 3. Re: Naming a MySQL table
              Level 7

              "jon@cmiwebstudio" <webforumsuser@macromedia.com> wrote in message
              news:glmeut$gd7$1@forums.macromedia.com...
              > using a gui to work with mysql will make your life a little easier. MySQL
              > has free tools you can download, or Navicat is an excellent software as
              > well.

              I'll chime in on Navicat, as well - It's a great tool!


              • 4. Re: Naming a MySQL table
                ArizonaJohn Level 1
                Wow, thank you so much David Powers. It works! I really appreciate your help. I will be sure to check out your website.

                Thanks,

                John