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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里