This question may be a duplicate but i couldn't find any solution in the questions.
It is a simple login method.
Basicly i am taking two parameters from the user and send them to the server, the server searches the database and return the result which matches the parameters that i send. And if there is no matching result than the method simply returns null so i can ask the user to correct the user name and the password.
Here is the code that i use to send the parameters;
@Override
protected User doInBackground(Void... params) {
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(0,new BasicNameValuePair("username",user.username));
dataToSend.add(1,new BasicNameValuePair("password",user.password));
HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams,CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.okanyakit.com/tez/FetchUserData.php");
User returnedUser = null;
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend));
HttpResponse httpResponse = client.execute(post);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
JSONObject jObject = new JSONObject(result);
if (jObject.length() == 0){
returnedUser = null;
}else {
String username = jObject.getString("username");
String password = jObject.getString("password");
String email = jObject.getString("email");
String phonenumber = jObject.getString("phonenumber");
String bloodtype = jObject.getString("bloodtype");
String birthday = jObject.getString("birthday");
String address = jObject.getString("address");
returnedUser = new User(username,password,email,phonenumber,bloodtype,birthday,address);
}
}catch (Exception e){
e.printStackTrace();
}
return returnedUser;
}
In here i am able to put both of the username and password to the list, but when it connects to the server i get an error and it says i sent only one parameter while it was expecting two.
I don't think there is a problem with my php code but i am not sure, so here it is ;
<?php
$con=mysqli_connect("89.19.30.210","okan_tez","okan_tez","okan_tez_andro");
$username = $_POST["username"];
$password = $_POST["password"];
mysqli_close($con);
$statement = mysqli_prepare("SELECT * FROM user WHERE username = ? AND password = ? ");
mysqli_stmt_bind_param($statement, "ss",$username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userid, $username, $password, $email, $phonenumber, $bloodtype, $birthday, $address);
$user = array();
while (mysqli_stmt_fetch($statement)){
$user [username] = $username;
$user [password] = $password;
$user [email] = $email;
$user [phonenumber] = $phonenumber;
$user [bloodtype] = $bloodtype;
$user [birthday] = $birthday;
$user [address] = $address;
}
echo json_encode($user);
mysqli_stmt_close($statement);
?>
And here is the debug screenshot ;

here is what is says in green font
Warning: mysqli_prepare() expects exactly 2 parameters, 1 given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 11
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, null given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 12
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, null given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 13
Warning: mysqli_stmt_store_result() expects parameter 1 to be mysqli_stmt, null given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 14
Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, null given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 15
Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, null given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 18
[]
Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, null given in /home/okanyakit.com/httpdocs/tez/FetchUserData.php on line 29
So what is the problem and how can i solve it ? Please the project deadline is in two days and i have lots of more problems. And i have a similiar problem with the registering part. I think if i can solve this i will be able to solve that too. Thanks.