User inputed data as mysql table entries

Discussion in 'PHP' started by designcentral, Jul 25, 2009.

  1. #1
    Hi there,

    I've just started using mysql & php. I want to know how I can use user inputed data for values in a table.

    Here is my source:
    <form method="post" action="add.php" />
    ID: <input type="text" name="id" />
    <input type="submit" />
    </form>
    HTML:
    add.php
    <?php
    
    $id = $_POST["id"];
    
    // Connects to your Database
    mysql_connect("localhost", "xxxxxxx", "xxxxxxx") or die(mysql_error());
    mysql_select_db("testing") or die(mysql_error());
    mysql_query("CREATE TABLE $id ( name VARCHAR(30),
    age INT, car VARCHAR(30))");
    
    Print "Your table has been created"; 
    
    ?>
    PHP:
    As you can see in my source, I am wanting to use the user inputed data ($id) to use for the table name.

    How do I go about doing this? - I am just mucking around...

    Cheers
     
    Last edited: Jul 25, 2009
    designcentral, Jul 25, 2009 IP
  2. designcentral

    designcentral Guest

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Also, after further investigation, I notice that values with a decimal point get rounded. eg When I added 22.50 it showed in phpmyadmin as 23... how do I keep it as 22.50 without it rounding?
     
    designcentral, Jul 25, 2009 IP
  3. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    While creating the table instead of int type you will have to give the decimal type and you can set the rounding like (0,2) 2 means the precision.


    If you are using the phpmyadmin its easy to implement
     
    HivelocityDD, Jul 25, 2009 IP