I don't know if this is going to help or not, but instead of escaping from php a few times for html, why don't you just use echo instead, so the coding will look neat. Just a suggestion if you don't mind.
Is the error said "unexpected $end" ? because you didn't tell the second problem.
I tried to correct it and the error is because of the first 'if' isn't close (the bracket is still open).
<div id="to_play">
<?php
if($rank>=1)
{
include"scripts/connect.php" ;
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$userquery_to_play = mysql_query("SELECT * FROM to_watch WHERE (to_watch_movie_id='$title') AND (to_watch_user_id='$loggedinusername')");
if (mysql_num_rows($userquery_to_play) > 0)
{
$user_to_play = mysql_result($userquery_to_play,$i,"to_watch_user_id");
echo "<div><span class='rulesub'>This is in your to play list</span><br></div>";
}
else if($rank>=1)
{
include"scripts/connect.php" ;
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$userquery_in_rating = mysql_query("SELECT * FROM rateing WHERE (title='$title') AND (user_id='$loggedinusername')");
}
else
{
echo "<script type='text/javascript'>";
// your javascript
echo "</script>";
echo "<form id='to-watch'>";
echo "<input type='hidden' name='MOVIE_ID_TO_WATCH' value='<?php echo $title; ?>'>";
echo "<input type='hidden' name='USER_ID_TO_WATCH' value='<?php echo $loggedinusername; ?>'>";
echo "<input type='submit' value='Add to my to play list'>";
echo "</form>";
echo "<div id='div_show_play' class='rulesub' align='left'>";
echo "</div>";
}
}
?>
sorry if it doesn't help.