Im trying to make a login php for an android app, I modified this php from a tutorial, the issue is I used to always get a response of "success" = 0 "message"= "Not all fields are filled", so I added a few print_r to see where is the problem now I only get this result aimatosnintendo , with are the inputs for username and password, so it's not even getting to the ifs, this is my code:
<?php
// array for JSON response
$response = array();
define('DB_USER', ""); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', ""); // database name
define('DB_SERVER', ""); // db server
// array for JSON response
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE);
// check for post data
print_r ($_POST['username']);
print_r ($_POST['password']);
if(isset($_POST['username'],$_POST['password'])) {
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT *FROM login WHERE username = $username AND password = $password";
$result = $conn->query($sql) or die (mysqli_connect_error());
print_r ($username);
if (!empty($result)) {
// check for empty result
if (mysqli_num_rows($result) > 0) {
$result = mysqli_fetch_array($result);
$loginfo = array();
$loginfo["name"] = $result["name"];
$loginfo["username"] = $result["username"];
$loginfo["password"] = $result["password"];
$loginfo["phone"] = $result["phone"];
$loginfo["email"] = $result["email"];
$loginfo["license"] = $result["license"];
//$loginfo["expiration"] = $result["expiration"];
// success
$response["success"] = 1;
// user node
$response["logina"] = array();
array_push($response["logina"], $loginfo);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "Wronglogin";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "Wronglogin";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Not all fields are filled";
// echoing JSON response
echo json_encode($response);
}
?>
db user password server and name are all correct i just deleted them in this post for safety, i have a code to register info on the database and it works but this one gets me stuck
im expecting a $response["success"] = 1; when username and password match with the database