PHP Parse error: syntax error, unexpected T_CLASS

I am new to PHP and I am making a forum. all files work, except for one file, add_topic.php.

This results in an error:

Parse error: syntax error, unexpected T_CLASS in / home / a 3885465 / public_html / add_topic.php on line 25

I know this is probably on the line:

}
else{
    echo "ERROR";
}
mysql_close();

but the whole code is below just in case.

If you have any ideas, it would be very grateful, thanks!


Code for 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();
?>
+3
source share
3 answers

Plus: You are a double quotation mark host.

$host=""host""; // Host name

replace it with

$host="host"; // Host name

But seriously: you should probably get a decent IDE!

+3
source

Line 25 is missing <?php:

<p class="p1"><span class="s1"></span><?php<span class="s2"><br>

It should be:

<p class="p1"><span class="s1"></span>&lt;?php<span class="s2"><br>
+1

:

, , ""host"" 1- .

echo "<a href=main_forum.php>View your topic</a>";

echo "<a href=\"main_forum.php\">View your topic</a>";

Finally, the code is full of features for SQL injection. Protect your entry before placing it in a request. There are all kinds of smart tricks for this, for example mysql_real_escape_string, tons of blog posts on the topic.

I personally think that using base64input and decoding it whenever I need to process it works best, t be mindful of the extra space.

+1
source

Source: https://habr.com/ru/post/1782568/


All Articles