Reputation: 678
I'm trying to send an INSERT query to my SQL DataBase but it doesn't work and no error is appearing but the query works if I send it from phpMyAdmin. here is my PHP code :
if ($_POST['func'] == 2) {
$dbca = taskdb();
$dbca->set_charset("utf8");
$mobileUser = $_POST['phone'];
$fullnameUser = $_POST['fullname'];
$usernameUser = $_POST['username'];
$sql = "INSERT INTO users (UserPhone, Username, UserFullname) VALUES (?,?,?)";
$result = $dbca->prepare($sql);
$result->bind_param("sss", $mobileUser,$fullnameUser,$usernameUser);
echo json_encode(array('profileUser' => 'DONE'));
}
and here is my java(client) code which is inside an AsyncT doInBacground:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.2.26/MyProject/fetchData.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("func", "2"));
nameValuePairs.add(new BasicNameValuePair("phone", Login.user_phone));
nameValuePairs.add(new BasicNameValuePair("fullname", fullname.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("username", username.getText().toString()));
Log.e("mainToPost", "mainToPost" + nameValuePairs.toString());
UrlEncodedFormEntity form;
form = new UrlEncodedFormEntity(nameValuePairs,"UTF-8");
httppost.setEntity(form);
HttpResponse response = httpclient.execute(httppost);
InputStream inputStream = response.getEntity().getContent();
Signup.InputStreamToStringExample str = new Signup.InputStreamToStringExample();
responseSignup = str.getStringFromInputStream(inputStream);
Log.e("response", "response -----" + responseSignup);
jsonresponse = new JSONObject(responseSignup);
} catch (Exception e) {
e.printStackTrace();
}
return null;
I'm getting "DONE" as the response in client but no row would be inserted into my DataBase. any help will be much appreciated.
Upvotes: 3
Views: 80
Reputation: 112
add
$result->execute();
after
$result->bind_param("sss", $mobileUser,$fullnameUser,$usernameUser);
in php file
Upvotes: 2