doutian3269 2016-02-12 21:58
浏览 147
已采纳

PHP代码不执行(PHP新手)

Okay so I am total noob in php since I recently started watching videos on php. So what I am trying to do is I have this html file:

<!DOCTYPE html>
<html>
    <head>
        <title>Testing PHP</title>
    </head>

    <body>
        <form action="action.php" method="POST">

            <input type="text" name="first">
            <input type="text" name="second">
            <input type="submit" value="Submitto!">
        </form>
    </body>
</html>

and then I have my action.php file which has this code:

<!DOCTYPE html>
<html>
    <head>
        <title>Testing PHP</title>
    </head>

    <body>

        <?php
            $first = $_POST['first'];
            $second = $_POST['second'];

            echo $first + $second;
        ?>

    </body>
</html>

However when I click on the submit button in my html file it sends me to a blank page. By the url I see that it has sent me to the right file but seems like the code doesn't execute.

PS: I tried searching on google but what I found was mostly stuff about apache not executing php which doesn't work for me since I try to run the files locally on my machine.

  • 写回答

2条回答 默认 最新

  • douchenhui5569 2016-02-12 22:58
    关注

    For Blank Page Problem: First you have to install a local server on your machine like apache then you have to request this page from the local server to run PHP locally on your machine.

    Here is the download page.

    For String concatenation:
    In php string concatenation operator is . sign not the + sign,so you have to use . operator instead of + operator.

    echo $first . $second;
    

    action.php

    <!DOCTYPE html>
    <html>
        <head>
            <title>Testing PHP</title>
        </head>
    
        <body>
    
            <?php
                $first = $_POST['first'];
                $second = $_POST['second'];
    
                echo $first . $second;
            ?>
    
        </body>
    </html>
    

    For more knowledge about String Operators read this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制