简体   繁体   English

MySQL查询的MySQL和PHP问题

[英]MySQL and PHP issue with MySQL query

I'm currently having a problem getting a variable to display in a php echo statement, and I don't know whats going wrong. 我目前在获取变量以显示在php echo语句中时遇到问题,而且我不知道出了什么问题。 This is the line I'm concerned about: 这是我关注的那一行:
$query="select password from ouser where pkey=".odb_get_pkey($user);

Is there anything wrong with this line? 这条线有什么问题吗?
Here is my code in context: 这是上下文中的代码:

function odb_get_pkey($username)
{
    $db=odb_connect();
    echo "Get the primary key".oLF();
    $query="select pkey from ouser where username='$username'";
    $pkey=odb_get_field($query,$db);
    echo $pkey.oLF();
}


function odb_get_password($user)
{
    $db=odb_connect();
    echo "Get the password".oLF();
    $query="select password from ouser where pkey=".odb_get_pkey($user);
    echo $query;
    $password=odb_get_field($query,$db);
    echo $password.oLF();
}


function odb_get_field($query,$db)
{
    $result = mysqli_query($db,$query);
    $row = mysqli_fetch_row($result);
    return($row[0]);
}

Currently I am just calling the odb_get_password function which will call the other two functions, and I just get the query select password from ouser where pkey= , and nothing after the equals sign. 目前,我只是在调用odb_get_password函数,该函数将调用其他两个函数,而且我只是select password from ouser where pkey=查询查询select password from ouser where pkey= ,等号后没有任何内容。 I don't know php or MySQL very well. 我不太了解php或MySQL。 Not sure what I'm doing wrong. 不知道我在做什么错。 Thank you for any help!! 感谢您的任何帮助!!

You never return the function value for odb_get_pkey . 您永远不会返回odb_get_pkey的函数值。 As you might know, echo prints the given variable to the page, while return returns it from a function. 如您所知, echo将给定的变量打印到页面上,而return从函数中返回它。 That explains why the $query variable has no value added to it in the end. 这就解释了为什么$query变量最后没有添加任何值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM