Получить значение из базы данных и вставить в строку в php - PullRequest
0 голосов
/ 03 марта 2019
<?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);
}

Здесь мне нужно вставить значение в эту строку пароля.
Заранее спасибо

1 Ответ

0 голосов
/ 03 марта 2019

mysqli_query() не возвращает строку.Возвращает mysqli_result, который вы можете получить.

$query = mysqli_query($con,"SELECT password FROM users WHERE mobile = '".$numberv."'");
if($query && $var = mysqli_fetch_array($query)) {
    $password = $var['password'];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...