我再次对STACKOVERFLOW hivemind有个疑问。这是交易,我试图从窗体插入我所有的$ _POST数据到一个MySQL表中。之前,我所做的:
INSERT INTO forms (Place, Date, Find, username, who_sponsored, hours, comments, howdiditgo, studentleader_name, studentleader_email, description)
VALUES ('$place', '$date','$where', '$username', '$who', '$hours', '$comments', '$how', '$description',)");
,所有的$值被宣布为$ _ POST [“广场”],$ _ POST [“日期”],等等。现在,我每次添加一个新的部分形式(如另一个textarea或其他),我只需要在mysql中创建一个新列而不是添加另一个$ _POST ['foo']。这是我曾尝试这样做:
// In the previous form, I have set all input ids to "service[]", so all this data would be in a more specific array than just $POST. Turns out all the $_POST['service'] stuff is null... Here's an example: <input name="placeofservice" type="text" id="service[]">
$forms = serialize($_POST['service']);
var_dump($forms);
mysql_query("INSERT INTO forms VALUES('$forms')")
or die(mysql_error());
我不断收到的错误是:列计数不在行1匹配值计数我知道这意味着我试图把太多的数据到数据库中,因为没有足够的列来适应数据。我已经来回查看,看看我是否正确(我认为我是这么做的)。仅供参考,这是我对的形式和MySQL表代码:
<form name="form1" method="post" action="process_form.php">
Place of Service</br>
<input name="placeofservice" type="text" id="service[]"></br>
Date of Service</br>
<input name="dateofservice" type="text" id="service[]"></br>
Where did you find this opportunity?</br>
<input name="where" type="text" id="service[]"></br>
What organization sponsored this opportunity?</br>
<input name="who_sponsored" type="text" id="service[]"></br>
How many hours did you work?</br>
<input name="hours" type="text" id="service[]"></br>
How did it go?</br>
<input type="text" id="service[]" name="howdiditgo" maxlength="100" /></br>
Description of Service:
<textarea name="description" id="service[]" COLS=40 ROWS=6></textarea></br>
Comments:
<textarea name="comments" id="service[]" COLS=40 ROWS=6></textarea></br>
Student Leader Name (If Applicable)</br>
<input name="studentleader_name" type="text" id="service[]"></br>
Student Leader Email(If Applicable)</br>
<input name="studentleader_email" type="text" id="service[]"></br>
<input type="submit" name="Submit" value="Submit">
</form>
MySQL表:
广场|日期|查找| form_id | who_sponsored |小时|评论| howdiditgo |描述| studentleader_name | studentleader_email |用户名
注意:我打算清理我的数据库内容/ $ POST数据,但为了我的目的,我将它遗漏了!如果您有任何问题随时问我会与编辑张贴在这里:标签:)
你不应该将序列化数据添加到数据库。你可能想使用面向文档的数据库,如[Mongo](http://www.mongodb.org/) – quantumSoup 2010-07-26 19:20:22
它可以保持非序列化? – 2010-07-26 19:39:36