再一次,我有一个关于stackoverflow hivemind的问题。这是交易,我正在尝试将表单中的所有$\u 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',)");
当所有的$values都声明为$\u post['place']、$\u post['date']等时,现在,每当我向表单添加新的部分(像其他文本区域或其他内容)时,我只需要在MySQL中创建一个新列,而不是添加另一个$\u 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:
$forms = serialize($_POST['service']);
var_dump($forms);
mysql_query("INSERT INTO forms VALUES('$forms')")
or die(mysql_error());
我一直收到的错误是:列计数与第1行的值计数不匹配。我意识到这意味着我试图将太多的数据放入数据库,因为没有足够的列来容纳数据。我来来回回地检查了一下,看我是否有这个权利(我想我有这个权利)。下面是我的表单和MySQL表代码,供参考:
Place of Service
Date of Service
Where did you find this opportunity?
What organization sponsored this opportunity?
How many hours did you work?
How did it go?
Description of Service:
Comments:
Student Leader Name (If Applicable)
Student Leader Email(If Applicable)
MySQL表:
地点日期查找表格谁小时评论howdiditgo描述学生负责人学生负责人电子邮件用户名
注意:我也计划清理我的数据库内容/$post数据,但为了我的目的,我把它遗漏了!如果您有任何问题,请随意提问,我将在此处发布edit:tags:。