dsfds4551 2016-09-12 13:40
浏览 51
已采纳

$ _POST在包含字符串时回显0

I made a basic HTML form working with post (it's a login form). The form itself works great, but when I try to work with the information contained in $_POST it goes wrong.

<?php
        // case : nothing submitted
        if (!isset($_POST['submit'])) {
        ?>
            <div class="login">
                <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
                    <p>Login</p>
                    <input type="text" id="username" placeholder="Username" name="username" />
                    <input type="password" id="password" placeholder="Password" name="password" />
                    <button name="submit">Submit</button>
                </form>
            </div>
        <?php
        // case : input form submitted
        } else {
            check_credentials();            
        }
?>

The problem is, it works fine when I do this ( above check_credentials() : echo $_POST['username']; echo $_POST['password'];

But when I do this : echo $_POST['username'] + " " + $_POST['password']; It echoes 0. As check_credentials() is a function that connects to my DB, the request isn't executed. Does someone have any idea of the possible cause ?

Greetz !

  • 写回答

1条回答 默认 最新

  • dongyan6235 2016-09-12 14:08
    关注

    You must use dots when concatenating in PHP. You probably "took" pluses from JS.

    It should look like in this example:

        <?php
        $a = "Hello ";
        $b = $a . "World!"; // now $b contains "Hello World!"
        $a = "Hello ";
        $a .= "World!";     // now $a contains "Hello World!"
        ?>
    

    And your example, if the variables are good:

      echo $_POST['username']." ".$_POST['password'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。