简体   繁体   English

该值未插入数据库

[英]The value is not inserting in database

I want to create an API for registration with OTP verification.我想创建一个用于注册 OTP 验证的 API。 The OTP is successfully sent on mobile.在移动设备上成功发送 OTP。 But the value of users is not inserted in the database.但是users的值并没有插入到数据库中。 Here is my signup code.这是我的注册码。

signup.php注册.php

<?php

include('config.php');

if( !empty($_POST['name']) && 
    !empty($_POST['mobile']) && 
    !empty($_POST['email']) && 
    !empty($_POST['password'])
  ){
        
    $name = $_POST['name'];
    $mobile = $_POST['mobile'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $str = mt_rand(100000, 999999); 
    
    $avalible_user_name="";
    $avalible_user_email="";
    
    $SQL= mysql_query("SELECT * FROM  users WHERE mobile='".$mobile."' ");
    while($row=mysql_fetch_array($SQL)){
        $avalible_user_name=$row['mobile'];
    }
    $SQL= mysql_query("SELECT * FROM  users WHERE email='".$email."' ");
    while($row=mysql_fetch_array($SQL)){
        $avalible_user_email=$row['email'];
    }   
        if($avalible_user_name=="" && $avalible_user_email==""){                
                    $SQLQUERY = mysql_query("INSERT INTO users SET 
                                            name = '" . $name."',
                                            mobile = '" . $mobile."',
                                            email = '" . $email."',
                                            password = '" . md5($password)."',
                                            otp = '".$str."',
                                            status = 0 ");
                                                            
                                            
                                        
                    $msg = "Your verification code:".$str.".";
                    $sms_text = str_replace(" ","%20",$msg);
                    $api_key = '2584909553545C';
                    $from = 'chkotp';
                    $api_url = "**My otp url**";
                    $response = file_get_contents($api_url);
                                    
                    die(json_encode(array("success"=>"true","message"=>"OTP sent to your mobile number please verify.")));                          
        }else{
             die(json_encode(array("success"=>"false","message"=>"Mobile or email all ready exits ")));
        }
}else{
         die(json_encode(array("success"=>"false","message"=>"Empty Parameters..!!")));
}
?>

Your insert query syntax is wrong,您的插入查询语法错误,

$new_pass = md5($password);
$SQLQUERY = mysql_query("INSERT INTO users( name, mobile, email, password) values('$name','$mobile','$email','$new_pass')");

I hope it helps.我希望它有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM