Hello

I am sure there is an easy way to do this, but I am stuck. I have a client who does not know anything about php, mysql, html or even computers for that matter. I have created a show ticket tracking system for them. My client needs to be able to create a new table for each event at their theater easily. What I would like to do is have a form with a text field where they can type the name of their event and when they click the submit button a table would be created in the mySQL database with the same name as the name typed in the text field. I think this would involve passing the information in the text field as a variable. but I am not sure. Below is the start of my code for the create table.

<?
$username = "";
$password = "";
$db_name = "";

mysql_pconnect("localhost","$username","$password");

echo
mysql_db_query("$db_name","CREATE table table_name (Seat_ID VARCHAR(15) NOT NULL,
PRIMARY KEY( Seat_ID ),
Level VARCHAR( 15 ) NOT NULL,
Section CHAR(1) NOT NULL,
Row CHAR(3) NOT NULL,
Seat CHAR(2) NOT NULL,
Status VARCHAR (15) NOT NULL )")
or die("Error! Reason: " . mysql_error());

?>

I would like to have the table_name replaced with the information that was typed into the text field in the form.

Thanks
Stan Forrest

    • [deleted]

    file.html:

    <form method="post" action="file.php">
    <input type="text" name="table_name">
    <input type="sybmit">
    <input type="hidden" name="create" value="true">
    </form>

    file.php:

    <?
    if($_POST['create'] == "true"){
    $username = "";
    $password = "";
    $db_name = "";

    mysql_pconnect("localhost","$username","$password");

    echo
    mysql_db_query("$db_name","CREATE table $_POST['table_name'] (Seat_ID VARCHAR(15) NOT NULL,
    PRIMARY KEY( Seat_ID ),
    Level VARCHAR( 15 ) NOT NULL,
    Section CHAR(1) NOT NULL,
    Row CHAR(3) NOT NULL,
    Seat CHAR(2) NOT NULL,
    Status VARCHAR (15) NOT NULL )")
    or die("Error! Reason: " . mysql_error());
    }
    ?>

    this should do it if you are using php >= 4.1.2

    ali

      I used the code you suggested but I received the following error

      Parse error: parse error, expecting T_STRING' orT_VARIABLE' or `T_NUM_STRING' in /home/virtual/site12/fst/var/www/html/ticketwizard/create_table/create.php on line 10

      here is the code I used

      <?
      if($_POST['create'] == "true"){
      $username = "";
      $password = "";
      $db_name = "";

      mysql_pconnect("localhost","$username","$password");

      echo
      mysql_db_query("$db_name","CREATE table $_POST['table_name'] (Seat_ID VARCHAR(15) NOT NULL,
      PRIMARY KEY( Seat_ID ),
      Level VARCHAR( 15 ) NOT NULL,
      Section CHAR(1) NOT NULL,
      Row CHAR(3) NOT NULL,
      Seat CHAR(2) NOT NULL,
      Status VARCHAR (15) NOT NULL )")
      or die("Error! Reason: " . mysql_error());
      }
      ?>

      Line 10 is where the error is taking place here is line 10 of the code above

      mysql_db_query("$db_name","CREATE table $_POST['table_name'] (Seat_ID VARCHAR(15) NOT NULL

      Thanks
      Stan Forrest

        • [deleted]

        maybe this code will work 😉. The only difference is that i defined the $table_name var.

        <?
        if($POST['create'] == "true"){
        $username = "";
        $password = "";
        $db_name = "";
        $table_name = $
        POST['table_name'];
        mysql_pconnect("localhost","$username","$password");

        echo
        mysql_db_query("$db_name","CREATE table
        $table_name
        (Seat_ID VARCHAR(15) NOT NULL,
        PRIMARY KEY( Seat_ID ),
        Level VARCHAR( 15 ) NOT NULL,
        Section CHAR(1) NOT NULL,
        Row CHAR(3) NOT NULL,
        Seat CHAR(2) NOT NULL,
        Status VARCHAR (15) NOT NULL )")
        or die("Error! Reason: " . mysql_error());
        }
        ?>

          Okay I tried the new code and there are no errors being returned but for some reason the table is not created in the database.

            Stan,

            Do this: print out your query using the PHP and use the command line or a program like phpMyAdmin (phpmyadmin.sourceforge.net) to execute the query manually. This way you can catch any errors with the query easily.

            -sridhar

              Write a Reply...