你们能帮我吗,伙计们,正在学习会话的概念,以帮助我进行用户登录。我做了以下 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%'> </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%'> </td>
</tr></table>
</body>
</html>";
?>
您需要在
字符串中转义"
。
它需要
<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');
(泰@Paul)
如评论中所述,最好不要回显如此大的 html 段。特别是在使用双引号时,php-parser 正在做很多不必要的工作。
使用单 qoutes 或转义此部分中的双引号:
<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>
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> ";
将其更改为
<form action='log.php' method='post'>
之后,您在以下行中也多次使用它 - 将双引号更改为单引号。
并且还更改:
header("location: index.html");
我认为你的第一个问题是逃避问题。当你做回显时,你必须为每个"字符打一个''