I want to make simple login server by XAMPP,
I use PHP and my intent action is it(registration):
Client send id, username, password via HTTP POST
Server check its database(using SELECT Query). if same id or username exist, registration fail and response("Registered Device or Username").
If there is no same id and username, registration success(using INSERT Query) and response("Register Success" or "Register Fail").
and here is my code.
<?php
$hostname_localhost ="localhost";
$database_localhost ="mydatabase";
$username_localhost ="root";
$password_localhost ="";
$id_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost, $id_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_localhost, $localhost);
$username = $_POST['username'];
$password = $_POST['password'];
$id = $_POST['id'];
$query_search_name = "select * from tbl_user where username = '".$username."'";
$query_search_id = "select * from tbl_user where id = '".$id."'";
$query_exec_name = mysql_query($query_search_name) or die(mysql_error());
$query_exec_id = mysql_query($query_search_id) or die(mysql_error());
$rows_id = mysql_num_rows($query_exec_id);
$rows_name = mysql_num_rows($query_exec_name);
if($rows_id != 0 || $rows_name != 0){
echo "Registered Device or Username";
exit;
} else {
$query_register = "INSERT INTO tbl_user (id, username, password) VALUES ('$id', '$username', '$password')";
$result = mysql_query($query_register) or die(mysql_error());
if($result == TRUE){
echo "Register Success";
} else {
echo "Register Fail";
}
exit;
}
?>
Client get 'Registered Device or Username' response but registration has been successful.
INSERT query works successfully and there is knew record in my database.
Then why client get(or server send) wrong response?
I'm poor at PHP... but if condition doesn't matter about php knowledge...