簡體   English   中英

從數據庫中獲取一個值並插入到php中的字符串中

[英]Get a value from database and insert into string in 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);
}

在這里,我需要粘貼該密碼字符串中的值。
提前致謝

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'];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM