php mysql insert

Discussion in 'PHP' started by 3.5supersonic, Nov 14, 2010.

  1. #1
    Hi

    i have a code like this, which gona use for add multiple comments to a record

    
    <script language="javascript">
    fields = 0;
    function addInput() {
        if (fields != 10) {
            var htmlText =  "<input type='text' value='' name='field[]' /><br />";
            var newElement = document.createElement('div');
            newElement.id = 'text';
    	 newElement.innerHTML = htmlText;
    
            var fieldsArea = document.getElementById('text');
    	fieldsArea.appendChild(newElement);
    
            fields += 1;
        } else {
            alert("Only 10 fields allowed.");
            document.form.add.disabled=true;
        }
    }
    </script>
    
    <form name="form" action="form.php" method="post">
    <input type="button" onclick="addInput()" name="add" value="Add input field" />
    <div id="text"></div>
    <br />
    <input type="submit" value="Submit" />
    </form>
    
    PHP:
    how can i insert all values submit from this code into a mysql table?


    sorry for language errors.

    Thanks
     
    3.5supersonic, Nov 14, 2010 IP
  2. vaidikkp

    vaidikkp Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Refer to W3Schools PHP tutorial. Its easy to understand and it will be of best help for this particular code and your future projects.
     
    vaidikkp, Nov 14, 2010 IP
  3. imocoder

    imocoder Member

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #3
    When you press the submit button, you'll get an array variable: $_POST['file']
    This will contain the value of the input fields.
    Eg. enter 3 input fields, values: a, b, c
    
    foreach ($_POST['field'] as $key=>$value) {
        echo $key.' value is '.$value."<br />";
    }
    
    PHP:
    Mainly field variables look in this way:
    
    [field] => Array
            (
                [0] => a
                [1] => b
                [2] => c
            )
    
    Code (markup):
     
    imocoder, Nov 15, 2010 IP