0
<?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

1
  • What's stray { for? Commented Jan 14, 2014 at 7:53

4 Answers 4

4
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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

What? Why delete echo?
you can use comment section
0

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];

Comments

0

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";
}
?>

2 Comments

thank u anil for the code but it is giving o/p as no record found, while the record is being added
check database connection then or try to execute the query (echo query in code and execute it in phpmyadmin)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.