Results 1 to 2 of 2

Thread: How to create table at mysql through form html with php

  1. #1
    Join Date
    Apr 2014

    How to create table at mysql through form html with php

    I hope anybody help me,I want to create table to MySQL through form and when I'm enter name of table and name of field and his type in form and click to button add field,the form create table under it that have the name of table and field name and his type and pin the name of table and add another field and his type and click to button that add another field to table and so on ,after I finished entering all fields and their types press at another button to add the name of table and their fields to MySQL with php I used that code for create table under form but I don't know how to take data from table html and use php to create table to database ?!
    PHP Code:
    <?php require 'connect.php';?>
    <script type="text/javascript">

    function updateForm() {

    var tablename = document.getElementById("tablen").value;


        var fieldname = document.getElementById("fieldn").value;

        var fieldtype = document.getElementById("fieldt").value;

        var table=document.getElementById("results");
        var row=table.insertRow(-1);
        var cell1=row.insertCell(0);
        var cell2=row.insertCell(1);



     <form name="order" method="post" id="frm1">
                <label for="tablename">Table Name </label>
                <input id="tablen" name="tablename" title="Please enter only alphabetic characters" type="text" size="28" />
                <label for="fieldname">Field Name</label>
                <input id="fieldn" name="fieldname" title="Enter item quantity" width="196px" />
               <label for="fieldtype">Field Type</label>

                <select name="fieldtype" id="fieldt" required="required">

    <option value="">Select</option>
    <option value="int(11) NOT NULL AUTO_INCREMENT">int(11)</option>
    <option value="decimal NOT NULL">decimal</option>
    <option value="varchar(50) NOT NULL">varchar(50)</option>
    <option value="text NOT NULL">text</option>
    <option value="char NOT NULL">char</option>
    <option value="longtext NOT NULL">longtext</option>
    <option value="year NOT NULL">year</option>
    <option value="date NOT NULL">date</option>
    <option value="time NOT NULL">time</option>
    <option value="binary NOT NULL">binary</option>
    <option value="float NOT NULL">float</option>

    <input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset" />
    <button type="button" onClick="updateForm();"/>Add To Table</button>

     <form  method="post" action="insert.php">
     <table id="results" border="2" width="360">
        <th scope="col" width="120">Table Name</th>
        <th scope="col" width="120">
     <p id="demo"></p>

        <th scope="col" width="120" id="fieldname1">Field Name</th>
        <th scope="col" width="120" id="fieldtype1">Field Type</th>

     <input type="submit" name="submit" value="Save Mode"  />


  2. #2
    Join Date
    Feb 2014
    You're using a file connect.php and sending some form data to insert.php, however, you haven't shown the code for either file. Since your JavaScript is using fields from both forms, I'm not sure whether you want to write data from both forms or just one. If you want to write it from both, it would be much easier to use only 1 <form>.

    Just a couple issues with your HTML first:

    - Any HTML input elements you wish to read data from will need to have a name attribute.
    - You do not need (and shouldn't for this) need a name attribute if the input type is submit or reset.
    - I'm guessing you want placeholder attributes instead of the title attributes in your input elements.
    - You have <label for = "fieldtype" >Field Type</label>, however, there is no other HTML element with a matching ID. I'm guessing you wanted it to be for your <select>, otherwise that label is functionally useless.

    Once you get that sorted out, in your insert.php file (or whichever other file will capture the table data and write to your MySQL), you'll need to do a few things:

    1) Use mysqli or PDO functions (NOT BOTH) to interact with your MySQL database. Don't use mysql functions since they will be depreciated.
    2) Check whether each $_POST variable is set, for example:
    PHP Code:
    if(isset($_POST['tablename'])) {
    // do something, possibly verification on the input
    } else {
    // data was not entered, do something

    3) If data verification was not yet performed, you need to do it.
    4) Write data to your MySQL table, preferably through prepared statements using mysqli or PDO functions.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.08675 seconds
  • Memory Usage 2,856KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates