-2

我收到第 7 行语法错误,意外的 T_CONSTANT_ENCAPSED_STRING 错误

<div id='login_form_container'>
    <div class='dInlineB' align="left">
        <label class='login_form_label' for='email'>Email:</label>
        <input type='email' name='email' id='email' tabindex="1" class='login_form_input'<?=(isset($_POST['email']) ? " value='']."'" : "");?>
    </div>
        <div class='dInlineB' align="left">
        <label class='login_form_label' for='password'>Password:</label>
        <input type='password' name='password' id='password' tabindex="2" class='login_form_input' />
    </div>
    <div align="left">
        <div class='login_form_spacer'>&nbsp;</div>
        <div class='dInline fs11'>
            <label for='login_form_stay'>
                <input type='checkbox' name='stayLogged' tabindex="3" checked='checked' value='1' id='login_form_stay' />

                Keep me logged in
            </label>
        </div>
4

4 回答 4

0
<input type='email' name='email' id='email' tabindex="1" class='login_form_input'<?=(isset($_POST['email']) ? " value='']."'" : "");?>

格式错误,请参阅以下正确行:

<input type='email' name='email' id='email' tabindex="1" class='login_form_input'<?=(isset($_POST['email']) ? " value='".$_POST['email']."'" : "");?>>

SO上突出显示的代码已经显示了您的错误所在。您错过的是将值添加$_POST到您的输入中。为了在字符串中添加 PHP 变量,您必须像这样附加 PHP:"this is a string" . $variable . " continued string"或使用单引号: 'this is a string' . $variable . ' continued string'

使用双引号还是单引号取决于您是否也希望能够使用内联变量,这适用于双引号,但不适用于单引号:"this $variable works inline" . 'but the $variable doesn\'t work here'. 有关双引号/单引号的更多信息:PHP 中单引号和双引号字符串有什么区别?

于 2013-11-13T07:50:20.470 回答
0

像这样重写行

  <input type='email' name='email' id='email' tabindex="1" class='login_form_input'<?=(isset($_POST['email']) ? " value='".$_POST['email']."'" : "");?>>
于 2013-11-13T07:51:36.180 回答
0

您可以更换:

<input type='email' name='email' id='email' tabindex="1" class='login_form_input'<?=(isset($_POST['email']) ? " value='']."'" : "");?>

和 :

<input type='email' name='email' id='email' tabindex="1" class='login_form_input'value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" >
于 2013-11-13T07:57:25.853 回答
0

将此行替换为

<input type='email' name='email' id='email' tabindex="1" class='login_form_input'<?=(isset($_POST['email']) /? " value='']."'" : "");?>
于 2013-11-13T07:57:45.867 回答