Reputation: 43
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
Upvotes: 3
Views: 177
Reputation: 1829
<?php
if(isset($_REQUEST['submit']))
{
$q= "INSERT INTO User_Roll(name) VALUES
('".$_REQUEST['es_price']."'),
('".$_REQUEST['es_price2']."'),
('".$_REQUEST['es_price3']."'),
('".$_REQUEST['es_price4']."'),
('".$_REQUEST['es_price5']."'),
('".$_REQUEST['es_price6']."'),
";
}
?>
YOU CAN use $_POST , $_GET and $_REQUEST,if you declare method="post" than you can able to fetch data using $_POST or same as get where $_REQUEST support both method get and post
Upvotes: 1
Reputation: 281
Try This:-
<?php
if(isset($_GET['submit']))
{
$q= "INSERT INTO User_Roll(name) VALUES
('".$_GET['es_price']."'),
('".$_GET['es_price2']."'),
('".$_GET['es_price3']."'),
('".$_GET['es_price4']."'),
('".$_GET['es_price5']."'),
('".$_GET['es_price6']."'),
";
//Execute Query
}
?>
You can only use $_POST or $_GET and $_REQUEST not both($_POST,$_GET)...depend what you declare in form method
Upvotes: 0
Reputation:
What you're asking for isn't completely clear. From what I gather you want to add multiple rows of the same field into a database.
I recommend something like this:
if(isset($_POST)){
$qty = count($_POST['cat_id']);
for($i = 0; $i < $qty; $i++){
$wpdb->insert( 'pricelist',
array(
'es_price' => $_POST['es_price'][$i],
),
array(
'%d',
)
);
}
}
Upvotes: 1
Reputation: 154
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)
Upvotes: 1