-3
 $sql = "SELECT temail FROM teacherusers WHERE tfullname='$teachername' limit 1";
 $result = mysql_query($sql);
 $value = mysql_fetch_object($result);
 $teacheremail2 = $value->temail;
 echo $teacheremail2;

echo $teacheremail2 returns nothing.

$teachername is valid and i have checked multiple times.

Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131

4 Answers4

0

It should be a two-dimensional array , you need $value[0]->temail

Mr.Zhang
  • 1
  • 1
0

The result of mysql_fetch_object($result) is an object(stdClass).

The explanation of object(stdClass) ican be found at this link

$sql = "SELECT temail FROM teacherusers WHERE tfullname='$teachername' limit 1";
$result = mysql_query($sql);
while ($value = mysql_fetch_object($result))
    {
    $teacheremail2 = $value->temail;
    echo $teacheremail2;
    }
-1

First off, you'll want to run the query directly against your database to ensure that the query returns some kind of result. Secondly, if that works, you'll want to echo $value directly to check that you are getting results back on the webpage.

Then you can check if temail is a field of $value

Jack
  • 412
  • 5
  • 13
-2
$sql = "SELECT temail FROM teacherusers WHERE tfullname='$teachername' limit 1";
 $result = mysql_query($sql);
while ($value = mysql_fetch_object($result))
    {
    $teacheremail2 = $value->temail;
    echo $teacheremail2;
    }

hope this help

  • 3
    This should work either way because of variable interpolation https://stackoverflow.com/questions/5605965/php-concatenate-or-directly-insert-variables-in-string – Jack Aug 29 '18 at 02:03
  • can you provide me the table and its data? i'll test in my local – arda sugriwo Aug 29 '18 at 02:14