dongyong1942 2019-03-03 15:52
浏览 120
已采纳

从数据库中获取值并在php中插入字符串

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

Here i need paste the value in that password string.
Thanks in Advance

  • 写回答

1条回答 默认 最新

  • duangai1916 2019-03-03 15:56
    关注

    mysqli_query() doesn't return a string. It return a mysqli_result, which you can fetch.

    $query = mysqli_query($con,"SELECT password FROM users WHERE mobile = '".$numberv."'");
    if($query && $var = mysqli_fetch_array($query)) {
        $password = $var['password'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题