从数据库中获取一个值并插入php中的字符串

从数据库中获取一个值并插入php中的字符串,php,mysql,mysqli,Php,Mysql,Mysqli,不返回字符串。它返回一个mysqli\u结果,您可以获取该结果 <?php require_once('dbConnect.php'); //This function will send the otp function sendOtp($numberv, $pass){ //This is the sms text that will be sent via sms $sms_content = "Welcome to : Your password is $pas

不返回字符串。它返回一个
mysqli\u结果
,您可以获取该结果

<?php
require_once('dbConnect.php');


//This function will send the otp
function sendOtp($numberv, $pass){
    //This is the sms text that will be sent via sms
    $sms_content = "Welcome to : Your password is $pass";

    //Encoding the text in url format
    $sms_text = urlencode($sms_content);

    //This is the Actual API URL concatnated with required values
    $api_url = 'xx'

    //Envoking the API url and getting the response
    $response = file_get_contents($api_url);

    //Returning the response
    return $response;
}


//If a post request comes to this script
if($_SERVER['REQUEST_METHOD']=='POST'){
    //getting username password and phone number.
    $numberv = $_POST['numberv'];

    //Generating a 6 Digits OTP or verification code
    $query = mysqli_query($con,"SELECT password FROM users WHERE mobile = '".$numberv."'");
    if($query && $var = mysqli_fetch_array($query)) {
    $v = $var['password'];
    $pass = echo $v;
    }


    //Importing the db connection script



    $result = mysqli_query($con,"SELECT * FROM otpverify WHERE phone = '".$numberv."' AND verified = '1'");


     if(mysqli_num_rows($result)>=1){
         $sql = "INSERT INTO forgotpass (numberv, pass) values ('$numberv','$pass')";
    }

    //If the query executed on the db successfully
    if(mysqli_query($con,$sql)){
        //printing the response given by sendOtp function by passing the otp and phone number


    }else{
        //printing the failure message in json
        echo 'Failure';
    }

    //Closing the database connection
    mysqli_close($con);
}

这可能意味着查询出错或找不到任何结果。请您尝试一下
$assoc=mysqli\u fetch\u assoc($query);var_dump($assoc)并检查您得到的结果是什么?
数组(1){[“密码”]=>字符串(32)“555FC43D1F5970DCC209F0F0F00208497”}
我只需要密码查询是正确的。因此,如果您使用我发布的代码并尝试打印($password)就在
$password=$var['password']下面
它不打印任何内容?因此,问题是在查询之后使用
$password
变量时。变量中的密码与预期一致。代码中几乎没有语法错误。你的问题是什么?你不应该仅仅发布你的代码并期望我们帮助你。
$query = mysqli_query($con,"SELECT password FROM users WHERE mobile = '".$numberv."'");
if($query && $var = mysqli_fetch_array($query)) {
    $password = $var['password'];
}