2

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.

1 Answer 1

1

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!

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

4 Comments

the same error is still there. I need to actually store the data received from the fields dynamically generated on by one in the database.
So try to debug and check what you can find in $_POST array (eg. using var_dump). And update your code.
$min = $mani->min_id; $max = $maxi->max_id; $number = $_POST['txt']; for($i = $min; $i<=$max ; $i++) { $Query ="INSERT INTO patients(d_id,number) VALUES($i,$number )"; this is the code
It's terrible.. You are not even filtering data from user. Also use var_dump on $_POST and you'll see what is wrong here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.