I have a form with multi-line input fields that I would like to same in MySQL table (each line will be a record in the table).

The form has the following fields

Hidden id field called id
First Name called fName
Last Name called lName

The form has 10 lines - each line has a unique hidden id value. The other two fields each has the same name and value on each of the 10 lines.
When the user clicks the submit button, I would like to go throught the $_POST value and group each line in an array and save it to the MySQL table called client.

I would very much appreciate you help - this is new to me.

Regards,

Asfaw

    a simple example:

    <?php
    if (!isset($_POST['submit']))
    {
    	echo '
    	<form action="" method="POST">
    
    1 first name: <input type="text" name="data[1][fName]"><br>
    1 last name: <input type="text" name="data[1][lName]"><br><br>
    
    2 first name: <input type="text" name="data[2][fName]"><br>
    2 last name: <input type="text" name="data[2][lName]"><br><br>
    
    3 first name: <input type="text" name="data[3][fName]"><br>
    3 last name: <input type="text" name="data[3][lName]"><br><br>
    
    <input type="submit" name="submit" value="submit">
    </form>
    ';
    }
    else
    {
    	foreach ($_POST['data'] as $value)
    	{
    		$sql = "INSERT INTO clients VALUES('" . $value['fName'] . "', '" . $value['lName'] . "')";
    		echo $sql . '<br>';
    	}
    }
    ?>
    

      if you're only using first & last names, why use a multi-line text box?

      Wouldn't a single line text box be better?

      Or am I just missing the point?

        devinemke - thank you very much for giving me an excelent answer.

        TobyRT - I am not sure you understood my question. The issue is to allow the user to enter 10 Frist and Last names each on a separte line and submit the form. When the user submit the form we want to process and enter it into the database - each line as one record. How do we do that? See devinemke code above. If you have a better alternative way let me know. Combining the first and last name in one field is not the issue. Even if you combine them together, you still have to enter 10 records in the database.

        Best regards to all.

        asfaw

          ahh - gotcha - I just misunderstood your question. Mike's answer makes sense to me!

            Write a Reply...