MYSQL SELECT查询不起作用

时间:2016-05-30 08:36:32

标签: php mysql

我想从数据库中选择电子邮件地址来发送电子邮件。以下是我的查询。

$userID=$_SESSION['userID'];

$select_query = mysql_query("SELECT * FROM employee WHERE emp_id = '$userID'");
$select_sql = mysql_fetch_array($select_query);
$name=$select_sql['manager_name'];

$select_query1 = mysql_query("SELECT email FROM employee WHERE employee.name='$name'");
$select_sql1 = mysql_fetch_array($select_query1);
$email=$select_sql1['email'];

但$ select_query1返回" NULL无效地址:"而不是正确的价值。我找不到这个问题。请帮忙 !

1 个答案:

答案 0 :(得分:1)

您正在使用$_SESSION['userID']获取表格employee中的所有数据,因此不要执行两次查询,只需尝试此操作

 $empID = $_SESSION['userID'];
 $query = mysql_query("SELECT * FROM employee WHERE emp_id=$empID");
 $result = mysql_fetch_array($query);
 $email = $result['email'];