Results 1 to 3 of 3
  1. #1

    Default Create Mysql table using PHP

    I want code for creating Mysql table, I dont want code for fix fields, I want to add any number of fields and with any name.

    I mean I want to create it dynamically using textboxes and combo boxes.

    Thank you

  2. #2

    Default

    Not sure about the exact place/purpose you intend to use it, but the following should help you suffice your requirements :

    Dealing with combo boxe in php is similar to the way you'd deal with text boxes. More-or-less similar steps are required to achieve the values.

    HTML :

    Code:
    <form action="process.php" method="POST">
    Name: <input type="text" name="name" /><br />
    DOB : <input type="text" name="dob" /><br />
    Gender : <select name="gender">
    <option value="M">Male</option>
    <option value="F">Female</option>
    </select><br />
    Country : <select name="country">
    <option value="US">United States of America</option>
    <option value="AU">Australia</option>
    <option value="CA">Canada</option>
    <option value="XX">XXXXX</option>
    </select><br />
    <input type="submit" value="Submit Info" />
    </form>
    In the php script for which you'd POST the form data, the variables can be accesses using $_POST[variablename].

    Code:
    echo $_POST['name'];
    echo $_POST['dob'];
    echo $_POST['gender'];
    echo $_POST['country'];
    These variables can be used in the query incase you intend to enter the information in MySQL

    Code:
    mysql_connect(mysql_server, username, password);
    mysql_select_db(db_name);
    mysql_query("INSERT INTO table_name (name, dob, gender, country) VALUES ('$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[country]')");
    This is most common type of going about it.

  3. #3

    Default

    this is how i would do it in php. suppose you want to create a table called categories:
    PHP Code:
    <?php
    $sql 
    =  ' CREATE TABLE categories ('
            
    ' categories_id int NOT NULL auto_increment,'
            
    ' categories_image varchar(64),'
            
    ' parent_id int DEFAULT \'0\' NOT NULL,'
            
    ' sort_order int(3),'
            
    ' date_added datetime,'
            
    ' last_modified datetime,'
            
    ' PRIMARY KEY (categories_id),'
            
    ' KEY idx_categories_parent_id (parent_id)'
            
    ' );';
    mysql_query($sql);
    ?>
    of course, you would first need to connect to your database server but i think you know it already.
    osc_osc

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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