Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert array data in php/mysql

Tags:

arrays

php

mysql

I have 6 text fields

<input id="es_price" name="es_price" placeholder="$ (AUD)" class="form-control" type="text">
<input id="es_price2" name="es_price2" placeholder="$ (AUD)" class="form-control" type="text">
<input id="es_price3" name="es_price3" placeholder="$ (AUD)" class="form-control" type="text">
<input id="es_price4" name="es_price4" placeholder="$ (AUD)" class="form-control" type="text">
<input id="es_price5" name="es_price5" placeholder="$ (AUD)" class="form-control" type="text">
<input id="es_price6" name="es_price6" placeholder="$ (AUD)" class="form-control" type="text">

and my database structure is

CREATE TABLE `es_prices_outcall` (
`es_prices_outcall_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`es_price` VARCHAR(50) NOT NULL DEFAULT '0',
PRIMARY KEY (`es_prices_outcall_id`)
)

I want, when i will submit data it should store in same database like an array. i don't want to create 6 column (es_price, es_price2, es_price3, es_price4, es_price5, and es_price6).

I m not very good in php, but i want to implement it.

Please help me, will be thankful to all of you.

As above i have mentioned all 6 text fields and their name/id, also i have shown my db structure, i want to insert all 6 fields data in my database, I don't want to change my text field name as i don't want to create 6 column to insert 6 text fields values, i want to use only one column "es_price" and want to all 6 text fields in 6 rows of "es_price" column.

I m not good enough to fix this, so i need proper guidance,

Thanks, Arshi

like image 842
Arshi Avatar asked Feb 17 '26 20:02

Arshi


1 Answers

Make a variable first which contain all price with comma.

$allPrice=$_POST['price1'].','.$_POST['price2'].','.$_POST['price3'].','.$_POST['price4'].','.$_POST['price5'].','.$_POST['price6'];

Then fire general insert query.

.........(`es_price`) value($allPrice)
like image 87
Niraj Karmick Avatar answered Feb 20 '26 08:02

Niraj Karmick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!