验证是否在php中选中了复选框 [英] verifying if checkbox is checked in php

查看:93
本文介绍了验证是否在php中选中了复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证是否在php中选中了我的复选框,如果是,我想回显 Hello word。
这是我的html代码:

I want to verify if my checkbox is checked in php and if it is, i want to echo "Hello word". Here is my html code :

<form class="checkclass">
<input type="checkbox" name="checkbox1"> 4K </input>
</form>

php:

 <?php
if (isset($_POST['checkbox1'])) {
    echo "Hello world!";
}
?>

但是它不起作用,我真的不知道该如何解决。
有人可以帮我吗?

But it doesn't work and i really don't know how to fix this. Can someone please help me ?

推荐答案

isset($ _ GET ['checkbox1'] ))不起作用,因为它正在检查URL查询字符串。不是表单提交。使用$ _POST代替$ _GET。就像这样:

isset($_GET['checkbox1'])) does not work because it is checking a URL query string. NOT a form submission. Use $_POST instead of $_GET. So it would be like this:

if (isset($_POST['checkbox1'])) {
// Go ahead and do stuff because it is checked
}

这篇关于验证是否在php中选中了复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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