D
D
Dmitry Isaev2018-04-12 12:47:32
PHP
Dmitry Isaev, 2018-04-12 12:47:32

How to write to mysql from input array?

There is an array in the base:

[{"name":"Оплата через Сбербанк Онлайн","description":"<small class=\"form-text text-muted\"><a href=\"\/how-buy\/\" target=\"_blank\">Инструкция<\/a> Как оплатить через сбербанк Онлайн<\/small>"},{"name":"Оплата по счёту","description":"описание"}]

There are fields unlimited number of fields.
<input type="text" class="form-control" name="payment_methods[][name]" value="">
<textarea class="form-control" name="payment_methods[][description]" rows="5"></textarea>

How to generate an array (or JSON) from these inputs.
Type:
$shipping_method = array(
array('name' => 'Оплата через Сбербанк Онлайн', 'description' => '<small class="form-text text-muted"><a href="/how-buy/" target="_blank">Инструкция</a> Как оплатить через сбербанк Онлайн</small>')
array('name' => 'Оплата по счёту', 'description' => ''),
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ildar Saribzhanov, 2018-04-12
@IsaevDimka

Add indexes to array elements

<input type="text" class="form-control" name="payment_methods[0][name]" value="">
<textarea class="form-control" name="payment_methods[0][description]" rows="5"></textarea>
<input type="text" class="form-control" name="payment_methods[1][name]" value="">
<textarea class="form-control" name="payment_methods[1][description]" rows="5"></textarea>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question