parse error? where?<

liunx

Guest
<?
include "database.php";


$id=$_POST['id'];

$comment=$_POST['comment'];

$author = $_POST['author'];

$date = $_POST['date'];

$time = $_POST['time'];

$type = $_POST['type'];

$ip = $_SERVER['REMOTE_ADDR'];

$message_length = strlen($comment);


$query2 = mysql_query("SELECT ip FROM comment WHERE ip= '" . $ip . "'");
$query3 = mysql_query("SELECT ip FROM comment2 WHERE ip= '" . $ip . "'");

if($query2 && mysql_num_rows($query2) > 0)
{
echo "Sorry, you have already posted 1 comments";
}
elseif($message_length < 1000 && $type=="tut" && mysql_num_rows($query2) = 0)
{


$ip = $_SERVER['REMOTE_ADDR'];
$content = nl2br(strip_tags($content,'<b><u><i>'));

$query = "INSERT INTO comment (id,comment,type,author,date,time,ip) VALUES ('$id','$comment','$type','$author','$date','$time','$ip')";

$result = mysql_query($query);

echo "Comment Added.";

mysql_close();


}
if($query3 && mysql_num_rows($query3) > 0)
{
echo "Sorry, you have already posted 1 comments";
}
elseif ($type=="tut" && mysql_num_rows($query3) = 0 && $message_length < 1000)
{

$ip = $_SERVER['REMOTE_ADDR'];

$content = nl2br(strip_tags($content,'<b><u><i>'));
$query = "INSERT INTO comment2 (id,comment,type,author,date,time,ip) VALUES ('$id','$comment','$type','$author','$date','$time','$ip')";

$result = mysql_query($query);

echo "Comment Added.";

mysql_close();

}
?>Why don't you take a look at the error message, as it gives you the exact line number where the parse error occurs. Post it here if you still can't find it.sorry, it was line 29.. and im sure after i fix that error, there maybe another parse error since i have another line just like that.Hi, I'm not sure if this is the problem... but it isin't normally good to assign values to variables in the conditional part of an if statement:

(mysql_num_rows($query2) == 0))

line 28( I think)

} elseif(($message_length < 1000) && ($type=="tut") && (mysql_num_rows($query2) == 0)) {Yep, that is the parse error, and it's on line 29. What PlyWooD suggested is probably what you want.

In case of future parse errors;
You must have gotten an error message similar to this:

Parse error: parse error, unexpected '=' in PHPDocument1 on line 29

This tells you a lot... The error is on line 29, and there's a misplaced '=' somewhere... All you have to do is to scan that line for that character, and you'll surely find the problem.not neccessarily Rydberg, it sometimes a line or two above or below it.

also Jeremy, in the future if you want to compare you need 2 equal signs.

mysql_num_rows($query2) = 0


will not cut it. make it a variable and then compare

$num = mysql_num_rows($query2);

$num == 0Yes of course, sometimes it's not exactly on the reported line, but most of the time, it is. Brackets might cause problems that occur on other lines, but those errors are not as common as others, especially if you indent your code properly.
 
Back
Top