[英]Get value from a select and insert id insetad of string into database - PHP MVC
[英]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.