【发布时间】:2020-02-20 03:05:08
【问题描述】:
您好,我正在执行一项任务,将 3 个检查项目输入到我的数据库中。我不能为此使用数组。
这是我的表格:
<p>What are your categories of interest? (Select as many as you'd
like below)</p>
<input name="industry" type="checkbox" value="industry"
/>Industry<br />
<input name="technical" type="checkbox" value="technical"
/>Technical<br />
<input name="career" type="checkbox" value="career" />Career<br />
这是我的 php:
$name = $_POST["name"];
$email = $_POST["email"];
$industry = $_POST["industry"];
$technical = $_POST["technical"];
$career = $_POST["career"];
$role = $_POST["role"];
include("includes/dbconfig.php");
$stmt = $pdo->prepare("INSERT INTO `contacts` (`contactid`, `name`,
`email`, `industry`, `technical`, `career` `role`) VALUES (NULL,
'$name', '$email', '$industry', '$technical', '$career',
'$role');");
$stmt->execute();
header("location:contactthankyou.php");
?>
我的数据库表有 3 列(行业、技术、职业)。
没有办法,请帮忙
我试过这个:
if(! isset($_POST["industry"]))
{$industry = "notchecked";
}else{
$industry = $_POST["industry"];}
没用……
还有这个:
$industry = false;
if( isset($_POST["industry"]))
{
$industry = true;
}
【问题讨论】:
-
-
这里缺少代码; HTML/表单的其余部分在哪里?
-
-
在问题中。没有人可以阅读评论中的代码
-
基本上,复选框字段仅在选中时才会发送到 PHP。所以你必须首先测试它的存在,比如
if ( isset($_POST['industry']) ){ // then it was checked
标签: php database forms checkbox