-5

I have an HTML form and a table inside it. Submit buttons and other lines of code are removed in this preview. Code below.

<form method="post" action="">
    <table>
        <thead>
            <tr>
                <th>Days</th>
                <th>Price</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input name="days[]" type="text"/></td>
                <td><input name="price[]" type="text"></td>
            </tr>
            <tr>
                <td><input name="days[]" type="text"/></td>
                <td><input name="price[]" type="text"></td>
            </tr>
        </tbody>
    </table>
</form>

Link to the image, how the form with the table looks:

Table image

So, whenever I click the submit button, I want to put the data of each column from table to MySQL database.

Then I need to display that data from database in the HTML table that should look like in the image:

Database data

I understand how to retrieve data from database and output it in the table, but I can't find out how to insert every table's column data into MySQL database when I click a submit button.

1
  • 2
    Welcome to Stack Overflow! This question is a little short on information. Can you share what you have tried, and what problems have you run into? Commented Mar 6, 2015 at 22:32

3 Answers 3

1

Take a look at $_POST['NAME OF INPUT']; and MySQL's INSERT INTO.

Sign up to request clarification or add additional context in comments.

Comments

0

Give each input field a unique name identifier 'name="days_a"' which you can get onSubmit using $_POST['days_a'],$_POST['days_b'] etc

Comments

0

At the very start of your script, before your doctype, try this:

<?php
if ($_POST)
{
    echo "<pre>" . print_r($_POST, true) . "</pre>";
}
?>

That should get you started! Your form elements correctly use the array approach, and investigating the format of the data you get back will reveal how to read the data you need. You will probably use a foreach() loop to iterate over each array from this superglobal.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.