Friday, September 13, 2013

to retrive a mysql data in php and echo the retrived data

to retrive a mysql data in php and echo the retrived data

<?php
$username = "root";
$password = "password";
$database = "meipolytechnic";
$link = mysql_connect("localhost", $username, $password);
$query = "SELECT rollno FROM users where username =
'".$_SESSION['MM_Username']."'";
mysql_select_db('meipolytechnic', $link);
$result = mysql_query($query) or die(mysql_error($link));
$num = mysql_num_rows($result);
mysql_close();
$rows = array();
$result = mysql_query($query) or die(mysql_error());
$rows = array();
while($r = mysql_fetch_row($result))
{
$rows[] = $r[0];
}
print_r($rows);
?>
This is my code i want to display the roll number of the currently logged
in user and when i run this code i get no database selected.

No comments:

Post a Comment