我在android中进行应用程序而且我不太了解php。这里我制作了一个PHP代码来插入我的android应用程序中的数据。如果我想检查mysql数据库中的用户已经存在电子邮件或联系方式,或者不然后我应该在哪里以及应该编码什么?请帮助。
我尝试触发select的查询并检查是否为真,但我认为这不是我写的。
这是我的php文件: 的 Individualuser_details.php:
<?php
// Include confi.php
include_once('confi.php');
if($_SERVER['REQUEST_METHOD'] == "POST"){
// Get data
$name = isset($_POST['name']) ? mysqli_real_escape_string($conn,$_POST['name']) : "";
$adhar = isset($_POST['adhar']) ? mysqli_real_escape_string($conn,$_POST['adhar']) : "";
$email = isset($_POST['email']) ? mysqli_real_escape_string($conn,$_POST['email']) : "";
$password = isset($_POST['password']) ? mysqli_real_escape_string($conn,$_POST['password']) : "";
$contact = isset($_POST['contact']) ? mysqli_real_escape_string($conn,$_POST['contact']) : "";
//echo $name.' no';
// Insert data into data base
$sql ="INSERT INTO id1536885_mydb.`individualuser_details` (`ID`, `name`, `adhar`, `email`, `password`, `contact`) VALUES (NULL, '$name', '$adhar', '$email', '$password', '$contact');";
// echo $sql;
$qur = mysqli_query($conn,$sql);
if($qur){
$json = array("status" => 1, "msg" => "Done User added!");
}else{
$json = array("status" => 0, "msg" => "Error adding user!");
}
}else{
$json = array("status" => 0, "msg" => "Request method not accepted");
}
@mysqli_close($conn);
header('Content-type: application/json');
echo json_encode($json);
?>