I have 6 text fields
我有6个文本字段
<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).
当我提交数据时它应该像数组一样存储在同一个数据库中。我不想创建6列(es_price、es_price2、es_price3、es_price4、es_price5和es_price6)。
I m not very good in php, but i want to implement it.
我的php不是很好,但是我想实现它。
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.
上面我已经提到了所有6个文本字段及其名称/ id,也显示我的数据库结构,我想在我的数据库插入6所有字段数据,我不想改变我的文本字段的名字我不想创建6列插入6文本字段值,我想只使用一列“es_price”,希望所有6文本字段在6行“es_price”专栏。
I m not good enough to fix this, so i need proper guidance,
我不够好来解决这个问题,所以我需要适当的指导,
Thanks, Arshi
谢谢,Arshi
4 个解决方案
#1
0
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
您只能使用$_POST或$_GET和$_REQUEST,而不能同时使用$_POST和$_GET
#2
1
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)
#3
1
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',
)
);
}
}
#4
1
<?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
您可以使用$_POST、$_GET和$_REQUEST,如果您声明方法=“post”,那么您可以使用$_POST或相同的$_POST来获取数据,也可以得到$_REQUEST支持的方法get和post。
#1
0
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
您只能使用$_POST或$_GET和$_REQUEST,而不能同时使用$_POST和$_GET
#2
1
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)
#3
1
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',
)
);
}
}
#4
1
<?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
您可以使用$_POST、$_GET和$_REQUEST,如果您声明方法=“post”,那么您可以使用$_POST或相同的$_POST来获取数据,也可以得到$_REQUEST支持的方法get和post。