2016-09-23 62 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扩展。