2016-09-23 9 views
0

タイトルのように、私のコードのprintf()echoの部分が正しく出力されるのに苦労しています。PHPでprintf()やechoが正しく動作しない

は、ここで最初のページ、単純な形式です:

<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"); ?> 

あなたが.htmlファイルにフォームを投稿している

+0

[PHPコードが実行されていない、コードページが表示されている可能性があります](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-ショー・オンザ・ザ・ページ) –

答えて

0

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

それは、デフォルトでは、設定することができますが、それはそのままその内容を返しますので、.htmlファイルは、PHPのソースファイルとして解析され、実行されません。代わりに.php拡張子を使用する必要があります。

関連する問題