我以某种方式理解了问题,但我不知道如何解决
我的脚本有效,但我不知道它是否与数据库连接
我的脚本已连接到android应用,并且某个地方连接断开,即使我在数据库中手动添加用户,也无法从应用中唱歌/唱歌
安卓
public static final String main = "https://localhost";
public static final String mainurl = "https://localhost/pubg/data/";
db_config.php
define('DB_USER',"root"); // db user
define('DB_PASSWORD',""); // db password (mention your db password here)
define('DB_DATABASE',"pub"); // database name
define('DB_SERVER',"localhost"); // db server
?>
db_connect.php
class DB_CONNECT {
public $con;
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
global $con;
// Connecting to mysql database
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysql_error());
// Selecing database
// $db = mysqli_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
global $con;
// closing db connection
mysqli_close($con);
}
}
?>
create_user.php
header('Content-Type: application/json');
// array for JSON response
$response = array();
// check for required fields
if (isset($_REQUEST['firstname']) && isset($_REQUEST['lastname']) && isset($_REQUEST['username']) && isset($_REQUEST['pubusername']) && isset($_REQUEST['email']) && isset($_REQUEST['mobile']) && isset($_REQUEST['password']) && isset($_REQUEST['other']) && isset($_REQUEST['promocode'])) {
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$username = $_REQUEST['username'];
$pubusername = $_REQUEST['pubusername'];
$email = $_REQUEST['email'];
$mobile = $_REQUEST['mobile'];
$password = $_REQUEST['password'];
$other = $_REQUEST['other'];
$promocode = $_REQUEST['promocode'];
// include db connect class
require_once(__DIR__.'/db_connect.php');
// connecting to db
$db = new DB_CONNECT();
$conn = $db->connect();
// POST all iid from users table
$results = mysqli_query($conn,"SELECT * FROM user WHERE mobile='$mobile' or email='$email' or username='$username'") or die(mysql_error());
// check for empty result
if (mysqli_num_rows($results) == 0) {
date_default_timezone_set("Asia/Calcutta");
$cur = date("Y-m-d H:i:s");
// mysql inserting a new row
$result = mysqli_query($conn,"INSERT INTO user (`userid`, `firstname`, `lastname`, `username`, `pubusername`, `gender`, `email`, `mobile`, `password`, `other`, `promocode`, `log_entdate`) VALUES (NULL, '$firstname', '$lastname', '$username', '$pubusername', NULL, '$email', '$mobile', '$password', '$other', '$promocode', '$cur')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
$rows = mysqli_fetch_array($results, MYSQLI_BOTH);
// echo $rows['mobile'];
// echo $mobile;
if($rows['mobile']==$mobile){
// successfully updated
$response["success"] = 2;
$response["message"] = "mobile is same.";
// echoing JSON response
echo json_encode($response);
} else if($rows['email']==$email){
// successfully updated
$response["success"] = 2;
$response["message"] = "email is same.";
// echoing JSON response
echo json_encode($response);
} else if($rows['username']==$username){
// successfully updated
$response["success"] = 2;
$response["message"] = "username is same.";
// echoing JSON response
echo json_encode($response);
}
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
我得到结果
{"success":0,"message":"Required field(s) is missing"}