我试图在html和php中创建一个简单的注册表单,但是我收到此错误消息并且不知道原因:
解析错误:语法错误,第47行/home/daygosta/public_html/dpicollege/register.php中的意外$结尾
这是我在register.php中的代码的链接 Click
答案 0 :(得分:3)
您的错误是heredoc没有很好地关闭。在你的文本EOT之前;不能成为任何角色。在你的代码中,我看到一个tab char。 您可以在documentation
中看到一个重大警告答案 1 :(得分:1)
在$ form变量中使用''
<?php
error_reporting(0);
require('config.php');
if(isset($_POST['submit'])){
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass1 == $pass2){
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($email1);
$email2 = mysql_escape_string($email2);
$pass = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);
}else{
echo "Sorry , your passwords do not match!</br>";
exit();
}
}else{
echo "Sorry, your emails do not match!</br>";
}
}else{
$form = '
<form acti method="POST">
First Name: <input type="text" name="name"/></br>
Last Name: <input type="text" name="lname"/></br>
User Name: <input type="text" name="uname"/></br>
Email Address: <input type="text" name="email1"/></br>
Confirm Email Address: <input type="text" name="email2"/></br>
Password: <input type="password" name="pass1"/></br>
Confirm Password: <input type="password" name="pass2"/></br>
<input value="Submit" type="submit" name="submit"/></br>
</form>
';
echo $form;
}
?>
答案 2 :(得分:0)
这将有效:
<?php
error_reporting(0);
require('config.php');
if(isset($_POST['submit'])){
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2){
if($pass1 == $pass2){
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($email1);
$email2 = mysql_escape_string($email2);
$pass = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);
}else{
echo "Sorry , your passwords do not match!</br>";
exit();
}
}else{
echo "Sorry, your emails do not match!</br>";
}
}else{
$form = '
<form acti method="POST">
First Name: <input type="text" name="name"/></br>
Last Name: <input type="text" name="lname"/></br>
User Name: <input type="text" name="uname"/></br>
Email Address: <input type="text" name="email1"/></br>
Confirm Email Address: <input type="text" name="email2"/></br>
Password: <input type="password" name="pass1"/></br>
Confirm Password: <input type="password" name="pass2"/></br>
<input value="Submit" type="submit" name="submit"/></br>
</form>
';
echo $form;
}
?>
答案 3 :(得分:0)
使用此而不是heredoc
$form = '
<form method="POST">
First Name: <input type="text" name="name"/></br>
Last Name: <input type="text" name="lname"/></br>
User Name: <input type="text" name="uname"/></br>
Email Address: <input type="text" name="email1"/></br>
Confirm Email Address: <input type="text" name="email2"/></br>
Password: <input type="password" name="pass1"/></br>
Confirm Password: <input type="password" name="pass2"/></br>
<input value="Submit" type="submit" name="submit"/></br>
</form>;
答案 4 :(得分:0)
根据Heredoc Syntax
,这个是正确的$form = <<<EOT
<form acti method="POST">
First Name: <input type="text" name="name"/></br>
Last Name: <input type="text" name="lname"/></br>
User Name: <input type="text" name="uname"/></br>
Email Address: <input type="text" name="email1"/></br>
Confirm Email Address: <input type="text" name="email2"/></br>
Password: <input type="password" name="pass1"/></br>
Confirm Password: <input type="password" name="pass2"/></br>
<input value="Submit" type="submit" name="submit"/></br>
</form>
EOT;
答案 5 :(得分:0)
错误的答案!他想使用heredoc,你的错误在EOT;
注意EOT结束前的空格。
答案 6 :(得分:0)
问题是,在关闭EOT之前你有空格,删除这个空格,你的脚本就可以了。