From f5d792b8f2fddc41e7689dcf2b65937613e35b4e Mon Sep 17 00:00:00 2001 From: wang_chengh <13383929+wang_chengh@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 17:48:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/cgi-bin/c_mysql_user&pwd.c | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/www/cgi-bin/c_mysql_user&pwd.c b/www/cgi-bin/c_mysql_user&pwd.c index 9ac210a..ccdc79b 100644 --- a/www/cgi-bin/c_mysql_user&pwd.c +++ b/www/cgi-bin/c_mysql_user&pwd.c @@ -28,6 +28,7 @@ int main() { } if (mysql_query(conn, + "CREATE DATABASE if NOT EXISTS router;" "CREATE TABLE IF NOT EXISTS users(id INT AUTO_INCREMENT " "PRIMARY KEY " "username VARCHAR(50) NOT NULL, password VARCHAR(255) NOT " @@ -86,30 +87,29 @@ int main() { return 1; } - cJSON *result_json = cJSON_CreateObject(); - - if ((row = mysql_fetch_row(res))) { - cJSON_AddNumberToObject(result_json, "code", 0); - } else { - cJSON_AddNumberToObject(result_json, "code", 1); - cJSON_AddStringToObject(result_json, "msg", "用户名或口令错误"); - } - - /* if ((row = mysql_fetch_row(res))) { - cJSON_AddStringToObject(result_json, "code", 0); - } else { - cJSON_AddStringToObject(result_json, "msg", "登录失败"); - } */ - - char *result_json_string = cJSON_Print(result_json); + // cJSON *result_json = cJSON_CreateObject(); // 输出 JSON 结果 printf("content-type: application/json;charset=utf-8\r\n"); printf("\r\n"); - printf("%s\n", result_json_string); - free(result_json_string); - cJSON_Delete(result_json); + if ((row = mysql_fetch_row(res))) { + // cJSON_AddNumberToObject(result_json, "code", 0); + printf( + "{\"code\": 0, \"data\": {\"user_id\": 111, \"nickName\": " + "\"老狄\"}}"); + } else { + printf("{\"code\": 1, \"msg\": \"用户名或口令错误\"}"); + // cJSON_AddNumberToObject(result_json, "code", 1); + // cJSON_AddStringToObject(result_json, "msg", "用户名或口令错误"); + } + + // char *result_json_string = cJSON_Print(result_json); + + // printf("%s\n", result_json_string); + + // free(result_json_string); + // cJSON_Delete(result_json); cJSON_Delete(p); mysql_free_result(res); mysql_close(conn);