duanbianweng5353 2015-11-15 21:04
浏览 15
已采纳

如何用ctype_digit检查文本框PHP [关闭]

This is my code, I get variable from textbox but nothing appears.

This code checks if a input is number:

this is a number

or not:

this is not a number

<?php
echo'<form method="post" action="">';
echo '<input type=text name=t/>';
echo'<input type=submit name=su/>';
echo'</form>';
if(isset($_POST['su']))
{
    if (ctype_digit($_POST['t'])) {
        echo "This is number.
";
    } else {
        echo "This is not a number.
";
    }
}
?>

All of code is in one page.

  • 写回答

3条回答 默认 最新

  • dougou6213 2015-11-15 21:59
    关注

    Your code is failing because you have unquoted elements/attributes.

    The following require quotes for:

    echo '<input type=text name=t/>';
                      ^^^^ ^^^^^^
    echo'<input type=submit name=su/>';
                     ^^^^^^ ^^^^^^^
    

    Modify your code to read as:

    <?php
    echo'<form method="post" action="">';
    echo '<input type="text" name="t"/>';
    echo'<input type="submit" name="su"/>';
    echo'</form>';
    if(isset($_POST['su']))
    {
        if (ctype_digit($_POST['t'])) {
            echo "This is number.
    ";
        } else {
            echo "This is not a number.
    ";
        }
    }
    ?>
    
    • Certain web browsers will not accept unquoted elements/attributes and will simply be ignored, such as the current version of Firefox and will fail silently even with error reporting set to catch/display, strangely enough.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB yalmip 可转移负荷的简单建模出错,如何解决?
  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?