douren0558 2016-09-29 08:48
浏览 23
已采纳

在查询字符串中插入100+个变量

I have an online survey format with approx 200 input / select fields which I now want to write into my database. Now, since I dont want to go through the tedious process of writing out every single variable one-by-one in the query string, I was hoping that there would be an easier way, eg. using an array?

  • 写回答

1条回答 默认 最新

  • douguyi3903 2016-09-29 08:53
    关注

    Here is a solution that I use. It requires that the database field names are the same as the <input> names:

    $querystring1 = ""; $querystring2 = "";
    foreach($_POST as $key => $var) {
        $querystring2 .= "'".$var."',"; $querystring1 .= $key.",";
    }   
    $insertquerystring = "(".$querystring1.") VALUES (".$querystring2.")";
    mysql_query("INSERT INTO `mytablename` $insertquerystring") or die(mysql_error());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动