将变量连接到 $_POST[] [英] Concatenate variable into $_POST[]
本文介绍了将变量连接到 $_POST[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在完成任务时,我得到了以下要求.
While working on task I got following requirement.
在 for 循环中,我必须在 db 中插入数据.我有带双引号的字符串 SQL 查询.我必须在 $_POST[]
In a for loop, I have to insert data in db.
I have SQL query in string with double quotes.
I have to concatenate counter variable inside $_POST[]
for($k=1;$k<=$total_questions;$k++)
{
$sql_insert_survey_question ="insert into survey_questions_options (question_detail,option_1) values ('".$_POST['survey_que\"$k\"']."','".$_POST['survey_que\"$k\"_option1']."')
$res_insert_que1=$obj->insert($sql_insert_survey_question);
}
请提供一些想法.
推荐答案
for($k=1;$k<=$total_questions;$k++)
{
$firstValueToInsert = mysql_real_escape_string($_POST['survey_que'.$k]);
$secondValueToInsert = mysql_real_escape_string$_POST['survey_que'.$k.'_option1']);
$sql_insert_survey_question ="insert into survey_questions_options (question_detail,option_1) values ('$firstValueToInsert','$secondValueToInsert')";
$res_insert_que1=$obj->insert($sql_insert_survey_question);
}
这篇关于将变量连接到 $_POST[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文