I'm new to PHP, and i'm making a forum. all the files work except one file, 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
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
$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();
?>
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!
You have an unescaped <?php
on line 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>
Three years later here I come:
Your parser is probably complaining about the quadruple quotes around ""host""
on the 1st line. Also
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.
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.
精彩评论