insert 100+ variables into query string

前端 未结 1 1546
名媛妹妹
名媛妹妹 2021-01-29 07:38

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 writ

相关标签:
1条回答
  • 2021-01-29 08:32

    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());
    
    0 讨论(0)
提交回复
热议问题