Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What I need to do is, if the user submits the form and there are blank inputs, the value of entered inputs will be retrieved. It is working fine if the name attribute is not an array, I tried the same thing here where the name attribute is an array, but it didn't work... This is the PHP code:
PHP
<?php
if(isset($_GET['add']){
$qp = ((isset($_POST['qp']) && $_POST['qp'] != '')?$_POST['qp']:'');
}
?>

and here is the HTML code:
PHP
<input name="qp[]" value="<?=$qp;?>" class="form-control">

I've got an error inside the input when submitting the form: "Warning: Array to string conversion"
Is the PHP code above is correct? How can I do it?

What I have tried:

I've also tried this:
PHP
<input name="qp[]" value="<?=$qp[];?>" class="form-control">

It says: Fatal error: Cannot use [] for reading
Posted
Updated 9-Apr-22 5:12am

1 solution

As I mentioned in your question at Check if the field is empty and the name is array in PHP[^], names must not include square brackets.
 
Share this answer
 
Comments
FRS4002 9-Apr-22 11:25am    
Then how can I send array values ??
Richard MacCutchan 9-Apr-22 11:40am    
You have to send them as separate items (see HTML Input Types[^]), which you unpack in the PHP code.
FRS4002 9-Apr-22 11:43am    
But I am using for loop, separate items means a lot of code to be done + not efficient
Richard MacCutchan 9-Apr-22 12:00pm    
You can only work with what is available.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900