Please I am trying to get this structure from a HTML form:
bulk_data: [
{
bank_code: "044",
account_number: "1234567832",
amount: 69000,
currency: "NGN",
meta: [
{
beneficiary_name: "Henry Augustus",
beneficiary_address: "No 5 Corpus Christi Avenue",
beneficiary_city: "Milano"
},
],
},
{
bank_code: "044",
account_number: "1234567834",
amount: 500,
currency: "USD",
narration: "Salary payment for April",
},
]
I tried the form elements like thus: But when I dd out the request, I do not get the request parameters as above.
<section>
<input type="text" name="bulk_data[][bank_code]"/>
<input type="text" name="bulk_data[][account_number]"/>
<input type="text" name="bulk_data[][amount]"/>
<input type="text" name="bulk_data[][currency]"/>
<input type="text" name="bulk_data[][meta][][beneficiary_name]" />
<input type="text" name="bulk_data[][meta][][beneficiary_address]" />
<input type="text" name="bulk_data[][meta][][beneficiary_city]" />
</section>
<section>
<input type="text" name="bulk_data[][bank_code]"/>
<input type="text" name="bulk_data[][account_number]"/>
<input type="text" name="bulk_data[][amount]"/>
<input type="text" name="bulk_data[][currency]"/>
<input type="text" name="bulk_data[][narration]"/>
</section>
I want to be able to print out the request to appear in the above structure. And also, how do I access the arrays assuming that I do not know how many arrays are coming into the php server. Plus how do I bulk store the individual array records into mysql database?
Any help?
name="bank_code", and then create the data structure in PHP, after proper input validation? That is a lot easier to do and maintain. Accessing objects/arrays is a basic language thing, you can easily look up. For storage you would use a query with INSERT. Perhaps it is better to ask a single question, per question? You will get a better answer for each issue.name="bank_code"wouldn't allow the form to contain multiple bank code fields, which is the OP's intentionI want to be able to print out the request to appear in the above structure.... for that you'll needjson_encode(), once you've assembled the submitted data in a PHP arrayhow do I access the arrays assuming that I do not know how many arrays...you know what a loop is, I assume?how do I bulk store the individual array records into mysql database...again, use a loop. Run an INSERT query for each record.