Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用复选框和输入字段插入数据库_Php_Checkbox_Insert - Fatal编程技术网

Php 使用复选框和输入字段插入数据库

Php 使用复选框和输入字段插入数据库,php,checkbox,insert,Php,Checkbox,Insert,我有如下表格: <input type="checkbox" name="type" value="wash"><label>Wash</label><br> <input type="checkbox" name="type" value="no wash"><label>No Wash</label><br> <label>Other (Specify)</l

我有如下表格:

 <input type="checkbox" name="type" value="wash"><label>Wash</label><br>
 <input type="checkbox" name="type" value="no wash"><label>No Wash</label><br>
        <label>Other (Specify)</label><br>
        <input name="type"><br>
Wash
禁止清洗
其他(指定)


如果您注意到这三个,我使用“type”作为输入名称。要点是,用户将获得两个选项,如果这两个选项都不适用于他们,他们应该在其他选项中输入一个值。现在在数据库中我有了字段类型,所以如果他们选择了前两个并在字段中输入了值,或者如果他们只在字段中写入了值,我仍然希望它成为类型字段的一部分。那么,我如何才能使它,如果他们选择了输入字段,它也应该插入“类型”

首先,最好使用单选按钮而不是复选框。 然后你可以做下面的事情

<input type="radio" name="type" value="wash"/><label>Wash</label>
<input type="radio" name="type" value="no_wash"/><label>No wash</label>
<input type="radio" name="type" value="other"/><label>Other</label>
<input type="text" name="other_type"/>
如果使用JS,甚至可以禁用文本框,除非用户选择第三个选项


编辑:如果我没有弄错你的评论,最简单的方法是:

if ($_REQUEST["type"] == "wash"){
    echo "Wash me please";
}else if ($_REQUEST["type"] == "no_wash"){
    echo "no wash";
}else if ($_REQUEST["type"] == "other"){
    echo "you want to ".$_REQUEST["other_type"];
}
<input type="checkbox" name="wash_me"/><label>Wash your car?</label>
<input type="text" name="other"/><label>What else can we do for you?</label>

你是说像这样的事吗

HTML:


请告诉我:)只会添加您可能希望根据
其他
收音机的值启用/禁用输入。我需要复选框来启用多个字段的选择。只需将其更改回复选框即可。它不应该改变任何东西。对不起,我没有理解正确,清洗/不清洗只是一个例子吗?所以你希望用户选择他是否想要洗车,然后他还想做什么,对吗?
if (isset($_REQUEST["wash_me"]){
    echo "wash my car please";
}
if (strlen($_REQUEST["other"]) != 0){
    echo "and do the following: ".$_REQUEST["other"];
}
<input type="checkbox" name="type[]" value="wash"/><label>Wash</label>
<input type="checkbox" name="type[]" value="no_wash"/><label>No wash</label>
Other type:
<input type="text" name="other_type"/>
if (!empty($_REQUEST['other_type']))
    $_REQUEST['type'][] = $_REQUEST['other_type'];
var_dump($_REQUEST['type']);