Ask Your Question
0

How can I add numerous rows to a database depending on the quantity of rows provided in the input form?

asked 2023-06-22 15:39:21 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-22 15:47:02 +0000

plato gravatar image

Assuming you are using a programming language to interact with the database, you can use a loop to insert multiple rows into the database based on the quantity provided in the input form. Here is an example code using PHP and MySQL:

// Retrieve the quantity from the input form
$quantity = $_POST['quantity'];

// Connect to the database
$con = mysqli_connect("localhost", "username", "password", "database_name");

// Loop through the quantity to insert multiple rows
for ($i = 0; $i < $quantity; $i++) {
  $query = "INSERT INTO table_name (column1, column2, column3) VALUES ('value1', 'value2', 'value3')";
  mysqli_query($con, $query);
}

// Close the database connection
mysqli_close($con);

In this example, $_POST['quantity'] is used to retrieve the quantity from the input form. Then, a loop is used to insert multiple rows based on the quantity provided. mysql_query() is used to execute the SQL insert statement. Finally, the database connection is closed using mysqli_close().

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-22 15:39:21 +0000

Seen: 14 times

Last updated: Jun 22 '23