未定义索引html [英] Undefined index html

查看:42
本文介绍了未定义索引html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是html的新手,所以我不确定我哪里出错了,但是我有以下代码(当用户按下Submit时,我正在创建一个表单并将值添加到数据库中).

I'm new to html so i'm unsure where im going wrong but i have the following code (i'm creating a form and adding values to the database when the user presses submit).

嵌套在表单中的复选框-

a checkbox nested in a form -

<label for="choice1">Windows 7</label>
<input type="checkbox" name="choice1"/>

,当用户按下添加按钮"时,我试图获取该值并将其存储在变量中,但找不到"choice1".

and when the user presses 'add button' i'm trying to get the value and store it in a variable but it cannot find 'choice1'.

$ choice1 = $ _ POST ['choice1'];

$choice1=$_POST['choice1'];

但是我得到"未定义索引:choice1 ".为什么是这样?

but i get "Undefined index: choice1". Why is this?

推荐答案

如果选中此复选框,则浏览器将其值与其他变量一起发送.

If the checkbox is checked, the browser sends its value with other variables.

如果未选中,则不会发送.

If it's not checked, it's not sent.

执行此操作:

$choice1 = isset($_POST['choice1']) ? $_POST['choice1'] : 0;

这篇关于未定义索引html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆