I see nothing wrong there except try doing this
$result = mysql_query("SELECT * FROM banners WHERE id='$rand'",$db)or die(mysql_error());
$all = mysql_fetch_row($result)or die(mysql_error());
That can help you. Most Likely you'll need to get rid of $db and the ,