简体   繁体   English

HTML显示在值区域中编写的PHP代码

[英]HTML showing PHP code written in value area

I have this HTML code. 我有这个HTML代码。 It is supposed to be a register form. 应该是注册表。 It is using a Session to store the information in case something is wrong so that the user doesn't have to re-enter the information again. 它使用会话来存储信息以防万一出现问题,从而使用户不必再次输入信息。 But somehow, it is writing the whole PHP code inside the value part. 但是不知何故,它是在value部分中编写了整个PHP代码。 Yes it is in the format .php and I am using WAMP Server. 是的,它采用.php格式,我正在使用WAMP Server。 I also tried to use APPServ but to no avail. 我也尝试使用APPServ,但无济于事。 Here is the code 这是代码

 <form action="register.php" method="post">
    <h1>Register Form</h1>
    <table>
        <tr>
            <td>Login name:</td>
            <td><input type="text" name="login_name" value="<?=(!empty($_POST['login_name'])) ? $_POST['login_name'] : ''?>" /></td>
        </tr>
        <tr>
            <td>First name:</td>
            <td><input type="text" name="first_name" value="<?=(!empty($_POST['first_name'])) ? $_POST['first_name'] : ''?>" /></td>
        </tr>
        <tr>
            <td>Last name:</td>
            <td><input type="text" name="last_name" value="<?=(!empty($_POST['last_name'])) ? $_POST['last_name'] : ''?>" /></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="pw1" /></td>
        </tr>
        <tr>
            <td>Confirm password:</td>
            <td><input type="password" name="pw2" /></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" name="email" value="<?=(!empty($_POST['email'])) ? $_POST['email'] : ''?>" /></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;"><input type="submit" name="register" value="Register!" /></td>
        </tr>
    </table>
</form>

The only problem I'm having is what I mentioned: The textboxes show the PHP code I wrote in the value part. 我遇到的唯一问题是我提到的内容:文本框显示了我在值部分中编写的PHP代码。 Everything else is working fine. 其他一切工作正常。 I am using Chrome in Window 8. I should also note that I sent this code to a friend and it worked just fine and the only difference we have is that he is using Windows 7. 我正在Window 8中使用Chrome。我还应该注意,我将此代码发送给了一个朋友,它工作正常,唯一的区别是他正在使用Windows 7。

<?= is short form of <?php echo . <?=<?php echo缩写。 In WAMP Server, short tags are off by default. 在WAMP Server中,短标签默认情况下处于关闭状态。 You can solve this problem in two ways : 您可以通过两种方式解决此问题:

  1. Change <?= to <?php echo <?=更改为<?php echo

    OR 要么

  2. Find php.ini file in wamp folder and change short_open_tag = On 在wamp文件夹中找到php.ini文件并更改short_open_tag = On

<?=替换为<?php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM