2016-09-23 40 views
0

中正常工作就像標題所示,我很難讓printf()echo部分代碼正確輸出文本。無法使用printf()或echo在php

這裏的第一頁,一張簡單的表格:

<form action="WhoYouAre.html" method="post"> 
     <Label>Name: <label><input type="text" name="name"><br> 
     <Label>Age: <label><input type="text" name="age"><br> 
     <Label>Address: <label><input type="text" name="address"><br> 
     <Label>State: <label><input type="text" name="state"><br> 
     <Label>Sex: <label><input type="text" name="sex"><br> 
     <input type="submit" value="Submit"> 
    </form> 

下面是針對的應該顯示的信息頁面的代碼:

<?php 
    session_start(); ?> 
    <?php 
    $_SESSION['name'] = $_POST['name']; 
    $_SESSION['age'] = $_POST['age']; 
    $_SESSION['address'] = $_POST['address']; 
    $_SESSION['state'] = $_POST['state']; 
    $_SESSION['sex'] = $_POST['sex']; 

    printf("Your name is %s. 
    Your age is %d. 
    Your address is %s, in the state of %s. 
    Your gender is %s.", $_SESSION['name'], $_SESSION['age'], 
    $_SESSION['address'], $_SESSION['state'], $_SESSION['sex']); 

    if($_SESSION['sex'] == 'male') 
     echo "<body style='background: url(http://images.mentalfloss.com/sites/default/files/styles/article_640x430/public/4hjh3kj634.png)'>"; 

    echo file_get_contents("PostPage.txt"); 
    ?> 

下面是輸出到我的網頁。

"; echo file_get_contents("PostPage.txt"); ?> 

任何提示??

+0

可能重複的[PHP代碼沒有被執行,而是代碼顯示在頁面上](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-顯示 - 上的頁面) –

回答

0

您可以發佈您的形式向.html文件:

<form action="WhoYouAre.html" method="post"> 

雖然它可以進行設置,默認.html文件不被解析和PHP源文件執行的,所以它會返回其內容不變。您將需要使用.php擴展。