检查$ _POST ['id']是否为数字,否则执行此操作 [英] Check $_POST['id'] is numeric then do this if not do otherwise

查看:192
本文介绍了检查$ _POST ['id']是否为数字,否则执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我似乎代码失败了:

Hello I seemed to be failing my code:

if (!empty($_POST['id'])) { 
    echo "empty";
} else {
    if (is_numeric($_POST['id'])) {
    echo "numeric!";
    } else {
    echo "not empty but not numeric how come?";
    }
}

我的浏览器网址:hxxp://localhost/upload/?id = 9

My browser url: hxxp://localhost/upload/?id=9

输出:非数字

怎么来?

请帮助.

推荐答案

应使用if(is_numeric($_GET['id'])) {

if (is_numeric($_GET['id'])) { 
    echo "yes numeric";
} else {
    echo "not numeric";
}

这篇关于检查$ _POST ['id']是否为数字,否则执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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