user5310490
user5310490

Reputation:

how to use $_REQUEST for an array in HTML

I'm generating a form with inputs like:

<input type="text" placeholder="# of patients" name="txt[1]" class=" form-control " />
<input type="text" placeholder="# of patients" name="txt[2]" class=" form-control " />
<input type="text" placeholder="# of patients" name="txt[3]" class=" form-control " />
<input type="text" placeholder="# of patients" name="txt[4]" class=" form-control " />

Now I want to get the values written in these fields using PHP. I'm using:

for($i = $maxi->max_id; $i<=$mani->min_id ; $i++) {
    $Query = "UPDATE general table set number_of_patient='".$_REQUEST['txt[$i]']."'" ; 
    mysql_query($Query);
}

But it does not work and says "Undefined index". Kindly solve me for this. Your help would be appreciated.

Upvotes: 2

Views: 65

Answers (1)

Elon Than
Elon Than

Reputation: 9765

First of all, don't use mysql_* functions. It's deprecated and will be removed from PHP.

You are using $_REQUEST['txt[$i]'] and PHP tells you truth about txt[$i] index. It simply doesn't exist.

To access your data you have to use $_POST['txt']. There will be array with sent data. Don't forget to filter user input!

Upvotes: 1

Related Questions