Kingsley John
Kingsley John

Reputation: 1

How to get multiple values from input box using php

This is the output of my code Output

Every item has its own item number. I will be entering randomly a value for 3 items, after doing so I will click on the add button and will be redirected to a confirmation page. How will I get the values with its corresponding item?

Thanks in advance for the answers :)

Upvotes: 0

Views: 806

Answers (2)

Vijayanand Premnath
Vijayanand Premnath

Reputation: 3605

You can bind or keep the text box name same as your database row ID so when you submit and in the target page you can redo the select and update the field in the database like

<input type="text" name="$id" />

in the target page use Select Query looping and give

Update table_name set field_name=$_REQUEST[$id] where id=$id

Upvotes: 1

Mani
Mani

Reputation: 2655

Use input name as array.

<input type="text" name="price[]" />
<input type="text" name="price[]" />
<input type="text" name="price[]" />
<input type="text" name="price[]" />
<input type="text" name="price[]" />

Get values like this

$price = $_POST['price'];
foreach($price as $key => $val ) {
  echo $val;
  echo "<br>";
}

Upvotes: 2

Related Questions