使用会话变量从数据库中检索数据

<?php

{
session_start();
include "dbconnect.php";

$email = $_SESSION['email'];
echo $email;
$query = "SELECT uid FROM master WHERE emailid = '$email' ";
$result = mysql_query($query);
$row=mysql_fetch_array($result);
while($row)
 {
  $uid=$row[1];

  echo $uid;

   }

} whats wrong in this code.it is giving the email but not able to retrieve uid using session variable email. please help

I don't know why you have { at beginning of your code, you should delete that. And second thing, delete echo $email; and you should have working code

while($row) {
   $uid = $row[1];
   echo $uid;
}

should be

while($row) {
   $uid=$row['uid'];  
   echo $uid;    
}

Try if this code works for you

session_start();
include "dbconnect.php";

$email = $_SESSION['email'];
//echo $email;
$query = "SELECT uid FROM master WHERE emailid = '$email' ";
$result = mysql_query($query);

while($row=mysql_fetch_array($result)){
    $uid=$row['uid'];
    echo $uid;
}

try $uid=$row[0] instead of $uid=$row[1]; Because $row is an array.Array always starts its counter form 0. here you have defined $uid=$row[1] which means it will display the result from second row of the result set..But there is no second row there is only one row which is "uid" so try $uid=$row[0] instead of $uid=$row[1];

try this:

<?php
session_start();
include "dbconnect.php";

$email = $_SESSION['email'];

$query = "SELECT uid FROM master WHERE emailid = '".$email."'";
$result = mysql_query($query);
if(mysql_num_rows($result)>0)
{
    $row = mysql_fetch_array($result);
    $uid = $row["uid"];
    echo $uid;
}
else
{
    echo "No record found";
}
?>