<?php
$droll=$_SESSION['roll'];
$sql=" SELECT name FROM hostel_register WHERE roll=$droll";
$result=mysql_query($sql);
echo $result;
?>
This code instead of returning name returns value "Resource id #5" everytime. Can someone help?
You forgot to fetch your results
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo $row['name'];
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
mysql_queryfunction returns a resultset object, not a scalar value, not an array, etc. (N.B. Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.) http://www.php.net/manual/en/function.mysql-query.php