【发布时间】:2013-07-05 00:58:29
【问题描述】:
请原谅我的幼稚和天真...我不是程序员!我已经在这 4 天中度过了最好的部分,我已经准备好参加 PHP 课程或强化治疗了。
场景:数据库内置于 mySQL。包含除 ID 和年龄之外的所有列 varchar(50) 的表 - 均为 INT。见下文,我只需要复选框链接列/字段中的“是”值。
我想使用同时具有文本框和复选框的表单插入数据。我认为最好的方法是 php 数组...??
表格:
<form action="process.php" method="post" enctype="multipart/form-data">
<label>Childname
<input type="text" name="textfield[childname]" />
</label>
<p>
<label>Age
<input type="text" name="textfield[age]" />
</label>
</p>
<p>
<label>Parent Name
<input type="text" name="textfield[parent_name]" />
</label>
</p>
<p>
<label>Contact Number
<input type="text" name="textfield[contact_no]" />
</label>
</p>
<p>Subjects<br />
<label>
<input type="checkbox" name="checkbox[scratch]" value="checkbox" />
Scratch</label>
<label>
<input type="checkbox" name="checkbox[app_inventor]" value="checkbox" />
App Inventor</label>
<label>
<input type="checkbox" name="checkbox[html]" value="checkbox" />
HTML</label>
</p>
<p>Sessions Attended<br />
<label>
<input type="checkbox" name="checkbox[nov12]" value="checkbox" />
Nov 2012</label>
</p>
<p>
<label>
<input type="checkbox" name="checkbox[dec12]" value="checkbox" />
Dec 2012</label>
</p>
<p> </p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
PHP 脚本:
<?php
include("config.php");
$childrecord = array("childname","age","parent_name","contact_no","scratch","app_inventor","html");
if(isset($_POST['childrecord'])){
$childrecord = $_POST['childrecord'];
$i = 0;
foreach ($childrecord as $key => $value); {
$i++;
$sql="INSERT INTO tblchildren (childrecord) VALUES ($_POST['childrecord'])";
mysql_query($sql);
}
?>
请帮忙! 提前谢谢....
【问题讨论】:
-
你的问题/你的问题是什么?
-
显然 PHP 不工作。我只学到了一点点,不知道这个论坛是由程序员(@Rajeev)“拥有”的。
-
我尝试将 isset 用于复选框,但我在表单中未选中的那些上得到未定义的索引,所以我认为数组,但我认为数组语法全错了....
-
@user2550346 此站点不归程序员所有,但由程序员主持。
标签: php mysql arrays post checkbox