I faced the following problem: During registration. The application sends data to the server, to the appropriate table, but upon confirmation of registration. I get that error every time
Сan ыomeone one tell me why this is happening?=(
D/Volley: [83] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://sample-tech.000webhostapp.com/Test/verification.php 0x7233d495 NORMAL 2> [lifetime=4050], [size=241], [rc=200], [retryCount=0]
D/EmailVerify: Verification Response: {"tag":"verify_code","error":false,"message":"Verify successful!","app_users_tb":{"id_users":"5ce4d1d2631456.69823541","f_name_users":"Adm","email_users":"sample@live.com","verified_users":"1","created_at_users":"2019-05-22 04:36:34"}}
W/System.err: org.json.JSONException: No value for user
W/System.err: at org.json.JSONObject.get(JSONObject.java:355)
W/System.err: at org.json.JSONObject.getJSONObject(JSONObject.java:574)
W/System.err: at tech.4pts.entry.EmailVerify$4.onResponse(EmailVerify.java:127)
W/System.err: at tech.4pts.entry.EmailVerify$4.onResponse(EmailVerify.java:117)
W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:78)
W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:106)
W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:136)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
Here’s the structure of the table in which the application entry is imported.
DROP TABLE IF EXISTS `app_users_tb`;
CREATE TABLE IF NOT EXISTS `app_users_tb` (
`id_users` varchar(23) NOT NULL,
`f_name_users` varchar(20) NOT NULL,
`s_name_users` varchar(20) NULL,
`b_day_users` date DEFAULT NULL,
`gender_of_users` varchar(3) DEFAULT NULL,
`email_users` varchar(30) NOT NULL,
`phone_users` int(20) DEFAULT NULL,
`zip_code_users` int(10) DEFAULT NULL,
`country_of_users` varchar(20) DEFAULT NULL,
`city_of_users` varchar(30) DEFAULT NULL,
`encrypted_password_users` varchar(250) NOT NULL,
`otp_users` int(6) NOT NULL,
`verified_users` int(1) NOT NULL DEFAULT '0',
`created_at_users` datetime DEFAULT NULL,
PRIMARY KEY (`id_users`),
UNIQUE KEY `email_users` (`email_users`),
UNIQUE KEY `phone_users` (`phone_users`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I thought this was due to an error in determining the data type in the bycatch. checked java code and sqlb everything is normal to tomuzhe records are created in the database, it means that with data types and php problems there is no then what is my error? (
private static final String KEY_ID_USERS = "id_users";
private static final String KEY_F_NAME_USERS = "f_name_users";
private static final String KEY_S_NAME_USERS = "s_name_users";
private static final String KEY_B_DAY_USERS = "b_day_users";
private static final String KEY_GENDER_OF_USERS = "gender_of_users";
private static final String KEY_EMAIL_USERS = "email_users";
private static final String KEY_PHONE_USERS = "phone_users";
private static final String KEY_ZIP_CODE_USERS = "zip_code_users";
private static final String KEY_COUNTRY_OF_USERS = "country_of_users";
private static final String KEY_CITY_OF_USERS = "city_of_users";
private static final String KEY_CREATED_AT_USERS = "created_at_users";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
private static final String CREATE_TABLE_USERS = "CREATE TABLE " + TABLE_USERS + "(" // Table Create Statements
+ KEY_ID_USERS + " TEXT PRIMARY KEY,"
+ KEY_F_NAME_USERS + " TEXT,"
+ KEY_S_NAME_USERS + " TEXT,"
+ KEY_B_DAY_USERS + " TEXT,"
+ KEY_GENDER_OF_USERS + " TEXT,"
+ KEY_EMAIL_USERS + " TEXT UNIQUE,"
+ KEY_PHONE_USERS + " INTEGER UNIQUE,"
+ KEY_ZIP_CODE_USERS + " INTEGER,"
+ KEY_COUNTRY_OF_USERS + " TEXT,"
+ KEY_CITY_OF_USERS + " TEXT,"
+ KEY_CREATED_AT_USERS + " TEXT" + ")";
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_USERS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
public void addUser(String id_users, String f_name_users, String email_users, String created_at_users) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_ID_USERS, id_users); // uid
values.put(KEY_F_NAME_USERS, f_name_users);
values.put(KEY_EMAIL_USERS, email_users);
values.put(KEY_CREATED_AT_USERS, created_at_users);
db.insert(TABLE_USERS, null, values);
db.close();
}
PHP script, when entering verification code, it looks like verified users = 1, even half getting errors «W/System.err: org.json.JSONException: No value for user
$user = $stmt->fetch();
if ($otp_users_ok == true) {
$response["error"] = false;
$response["message"] = "Verify successful!";
$response["app_users_tb"]["id_users"] = $user["id_users"];
$response["app_users_tb"]["f_name_users"] = $user["f_name_users"];
$response["app_users_tb"]["email_users"] = $user["email_users"];
$response["app_users_tb"]["verified_users"] = $user["verified_users"];
$response["app_users_tb"]["created_at_users"] = $user["created_at_users"];
die(json_encode($response));
} else {
$response["error"] = true;
$response["message"] = "Invalid Credentials!";
die(json_encode($response));
}
}
Java verification process code
private void verifyCode(final String email_users, final String otp_users) {
String tag_string_req = "req_verify_code";// Tag used to cancel the request
pDialog.setMessage("Checking in ...");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
Functions.OTP_VERIFY_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Verification Response: " + response);
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
JSONObject json_user = jObj.getJSONObject("user");
Functions logout = new Functions();
logout.logoutUser(getApplicationContext());
db.addUser(json_user.getString(KEY_ID_USERS),
json_user.getString(KEY_F_NAME_USERS),
json_user.getString(KEY_EMAIL_USERS),
json_user.getString(KEY_CREATED_AT_USERS));
session.setLogin(true);
Intent upanel = new Intent(EmailVerify.this, HomeActivity.class);
upanel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(upanel);
finish();
} else {
Toast.makeText(getApplicationContext(), " Wrong verification Code", Toast.LENGTH_LONG).show();
textVerifyCode.setError("Wrong verification Code");
}
} catch (JSONException e) {
e.printStackTrace(); //!!!!!
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Verify Code Error: " + error.getMessage());
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> paramsUsers = new HashMap<>();
paramsUsers.put("tag", "verify_code");
paramsUsers.put("email_users", email_users);
paramsUsers.put("otp_users", otp_users);
return paramsUsers;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded");
return params;
}
}; MyApplication.getInstance().addToRequestQueue(strReq, tag_string_req);
}