php PHP解析错误:语法错误,意外的T_CLASS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4553401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Parse error: syntax error, unexpected T_CLASS
提问by Niall Paterson
I'm new to PHP, and i'm making a forum. all the files work except one file, add_topic.php.
我是 PHP 新手,正在制作一个论坛。除了一个文件 add_topic.php 之外,所有文件都可以工作。
It gives me an error saying:
它给了我一个错误说:
Parse error: syntax error, unexpected T_CLASS in /home/a3885465/public_html/add_topic.php on line 25
解析错误:语法错误,第 25 行 /home/a3885465/public_html/add_topic.php 中的意外 T_CLASS
I know it is probably on the lines:
我知道它可能就行了:
}
else{
echo "ERROR";
}
mysql_close();
but the whole code is below just in case.
但为了以防万一,整个代码都在下面。
If you have any idea, it would be really appreciated, thanks!
如果您有任何想法,将不胜感激,谢谢!
The Code for add_topic.php
add_topic.php 的代码
$host=""host"";
$username="username";
$password="password";
$db_name ="database_name";
$tbl_name="forum_question";// Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get data that sent from form
$topic= $_POST['topic'];
$detail= $_POST['detail'];
$name= $_POST['name'];
$email= $_POST['email'];
$datetime=date("d/m/y h:i:s");//create date time
$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic',
'$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=main_forum.php>View your topic</a>";
else{
echo "ERROR";
}
mysql_close();
?>
回答by Oliver A.
Plus: you "double quotet Host.
加上:你“双引号主机。
$host=""host""; // Host name
replace it with
将其替换为
$host="host"; // Host name
But seriously: you should probably get yourself a decent IDE!
但说真的:你应该给自己找一个像样的 IDE!
回答by rath
Three years later here I come:
三年后我来了:
Your parser is probably complaining about the quadruple quotes around ""host""
on the 1st line. Also
您的解析器可能在抱怨""host""
第一行周围的四重引号。还
echo "<a href=main_forum.php>View your topic</a>";
should be
应该
echo "<a href=\"main_forum.php\">View your topic</a>";
Finally the code is full of opportunities for SQL injection. Shield your input before putting it in a query. There are all sorts of clever tricks to do that, like mysql_real_escape_string
and tons of blog posts devoted to the subject.
最后,代码充满了 SQL 注入的机会。在将其放入查询之前屏蔽您的输入。有各种各样的聪明技巧可以做到这一点,例如 mysql_real_escape_string
和大量专门针对该主题的博客文章。
I personally find that using base64
on the input, and decoding it whenever I need to process it works best, if you don't mind the extra space.
我个人发现base64
,如果您不介意额外的空间,则在输入上使用并在需要处理时对其进行解码效果最佳。
回答by Nick Craver
You have an unescaped <?php
on line 25:
您<?php
在第 25 行有一个未转义的:
<p class="p1"><span class="s1"></span><?php<span class="s2"><br>
It should be:
它应该是:
<p class="p1"><span class="s1"></span><?php<span class="s2"><br>