0

ユーザーのログインに役立つセッションの概念を学んでいます。次のphpコードを実行しましたが、次のエラーが発生します。解析エラー:構文エラー、予期しないT_STRING、予期しない'、'、または ' ; ' 12行目のC:\ wamp \ www \ w3\login.phpにあります。

<?php
    session_start();
        echo "      <html>
                    <body>
                    <br/>
                    <table border = '0'  width = '100%' height = '100%'><tr>
                    <td width = '30%' height = '100%'>&nbsp;</td><td valign = 'top'>    
                    <a href='display.html'>Display</a>";
    if(!isset($_SESSION['loged'])){     
        echo "      <fieldset><legend>Log In</legend>
                    <center><table border = '0'>
                    <form action="log.php" method="post">
                    <tr><td>Username:</td><td><input type="text" name="username" /></td></tr>   
                    <tr><td>Password:</td><td><input type="password" name="pwd" /></td></tr>
                    <tr><td colspan = '2' align = 'center'><input type="submit" value="submit" /></td></tr>
                    </form>
                    </table></center>
                    </fieldset> ";
    }

    else{
        header(location:index.html);
        die();
    }
        echo "      </td><td width = '30%' height = '100%'>&nbsp;</td>  
                    </tr></table>       
    </body>
    </html>";
?>
4

5 に答える 5

4

文字列でエスケープする必要があり"ます。

それはする必要があります

<form action=\"log.php\" method=\"post\">

またはそれ以上:

<form action='log.php' method='post'>

さらに良い:

echo ' .... action="..." '

一番:

 <?php php-code... ?>
 HTML-Code 
 <?php php-code... ?>

もちろん、これはコードのすべての行に必要です。

編集:

また、次のように記述する必要があります。

header('location:index.html');

(ティ@ポール)

コメントで述べたように、そのような大きな html セグメントをエコーし​​ない方がよいでしょう。特に二重引用符を使用する場合、php-parser は多くの不要な作業を行っています。

于 2012-05-14T12:25:27.713 に答える
1

この部分では、一重引用符を使用するか、二重引用符をエスケープします。

<form action="log.php" method="post">
   <tr><td>Username:</td><td><input type="text" name="username" /></td></tr>   
   <tr><td>Password:</td><td><input type="password" name="pwd" /></td></tr>
   <tr><td colspan = '2' align = 'center'><input type="submit" value="submit" /></td></tr>
</form>
于 2012-05-14T12:27:04.547 に答える
1
echo "      <fieldset><legend>Log In</legend>
                    <center><table border = '0'>
                    <form action="log.php" method="post">
                    <tr><td>Username:</td><td><input type="text" name="username" /></td></tr>   
                    <tr><td>Password:</td><td><input type="password" name="pwd" /></td></tr>
                    <tr><td colspan = '2' align = 'center'><input type="submit" value="submit" /></td></tr>
                    </form>
                    </table></center>
                    </fieldset> ";

見積もりに問題があります。

試す

echo "      <fieldset><legend>Log In</legend>
                        <center><table border = '0'>
                        <form action='log.php' method='post'>
                        <tr><td>Username:</td><td><input type='text' name='username' /></td></tr>   
                        <tr><td>Password:</td><td><input type='password' name='pwd' /></td></tr>
                        <tr><td colspan = '2' align = 'center'><input type='submit' value='submit' /></td></tr>
                        </form>
                        </table></center>
                        </fieldset> ";
于 2012-05-14T12:27:11.097 に答える
1

に変更します

<form action='log.php' method='post'>

その後、次の行にも数回あります。二重引用符を一重引用符に変更します。

また、変更します。

header("location: index.html");
于 2012-05-14T12:27:20.287 に答える
0

あなたの最初の問題は逃げる問題だと思います。あなたがあなたのエコーをするとき、あなたはすべての"文字のために\をpuyしなければなりません

于 2012-05-14T12:28:32.187 に答える