apple軟件開發,ios開發 訪問mysql_iOS開發實戰-時光記賬Demo 網絡版

 2023-10-15 阅读 30 评论 0

摘要:寫在前面apple軟件開發、弄了下個人站...防止內容再次被鎖定...所有東西都在這里面welcome~ios 開發?個人博客之前寫了一個本地數據庫版本 戳這里mysql入門?現在這個就是增加了后臺 登錄注冊頁面以及web的上傳記錄展示頁面含有少量php有興趣可以看下另外demo中包括數據庫操作

寫在前面

apple軟件開發、弄了下個人站...防止內容再次被鎖定...所有東西都在這里面

welcome~

ios 開發?個人博客

之前寫了一個本地數據庫版本 戳這里

mysql入門?現在這個就是增加了后臺 登錄注冊頁面以及web的上傳記錄展示頁面

含有少量php有興趣可以看下

另外demo中包括數據庫操作、json、網絡請求等都沒有用到第三方庫,所以網絡方面的邏輯可能有所欠缺,大神請輕拍。

效果

4a490eb17624

效果.gif

分析

很簡單的分析把大致需要編寫的模塊列出

4a490eb17624

服務器交互.png

客戶端部分

分析

與本地版的demo相比主要是多了服務器請求操作

新增數據庫內容:

Users表

與Tally表關系:一對多

4a490eb17624

user表

相反Tally與Users的關系就是:一對多

4a490eb17624

tally表

flag字段 決定是否上傳

需要發送請求的位置

登錄

注冊

登錄成功后第一次加載

新增賬單

修改賬單

刪除賬單

代碼

登錄

登錄時向服務器發送用戶名和密碼,當然只有兩個結果:未注冊 和 密碼錯誤

#import "LoginViewController.h"

@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userNameField;

@property (weak, nonatomic) IBOutlet UITextField *userPswField;

@end

@implementation LoginViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"登錄";

[[CoreDataOperations sharedInstance] loadTallyTypeToSqlite];

// Do any additional setup after loading the view.

}

- (void)viewWillAppear:(BOOL)animated{

self.userNameField.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];

self.userPswField.text = nil;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

//去注冊

- (IBAction)clickRegister:(id)sender {

[self.userPswField resignFirstResponder];

[self.userPswField resignFirstResponder];

}

//輸入檢查 6-20為正常字符

- (BOOL)inputCheck:(NSString*)passWord{

NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";

NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];

return [passWordPredicate evaluateWithObject:passWord];

}

//去登錄

- (IBAction)clickLogin:(id)sender {

//輸入檢查

BOOL userNameCheck = [self inputCheck:self.userNameField.text];

BOOL userPswCheck = [self inputCheck:self.userPswField.text];

if (!userNameCheck | !userPswCheck) {

[self showAlertInfoWithTag:999 andMessage:@"用戶名或密碼出錯\n請輸入6-20位合法字符"];

return;

}

//鍵盤收起

[self.userPswField resignFirstResponder];

[self.userNameField resignFirstResponder];

ServerOperations *op = [ServerOperations sharedInstance];

op.delegate = self;

[op loginWithUser:self.userNameField.text andPsw:self.userPswField.text];

}

//登錄結果

- (void)didLoginBackWithTag:(int)tag{

[self loginAlertWithReslut:tag];

}

//驗證登錄

- (void)loginAlertWithReslut:(int)result{

switch (result) {

case 0:

//連接遠程數據庫失敗

[self showAlertInfoWithTag:result andMessage:@"連接遠程數據庫失敗"];

break;

case 1:

//驗證成功

[self performSegueWithIdentifier:@"toHome" sender:nil];

break;

case 2:

//密碼錯誤

[self showAlertInfoWithTag:result andMessage:@"密碼錯誤"];

break;

case 3:

//用戶不存在

[self showAlertInfoWithTag:result andMessage:@"用戶名不存在\n請注冊"];

break;

default:

break;

}

}

//彈出提示框

- (void)showAlertInfoWithTag:(int)tag andMessage:(NSString*)message {

UIAlertController *alertVC =[UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];

[alertVC addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil]];

if (tag == 3) {

[alertVC addAction:[UIAlertAction actionWithTitle:@"注冊" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

[self performSegueWithIdentifier:@"toRegister" sender:nil];

}]];

}

[self presentViewController:alertVC animated:YES completion:nil];

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

NSLog(@"準備push");

//本地保存用戶名

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLoaded"];

[[NSUserDefaults standardUserDefaults] setObject:self.userNameField.text forKey:@"userName"];

}

@end

注冊

注冊也很簡單,發送注冊信息給服務器,服務器判斷下用戶名是否存在就行。

#import "RegisterViewController.h"

@interface RegisterViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userNameField;

@property (weak, nonatomic) IBOutlet UITextField *userPswField;

@end

@implementation RegisterViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"注冊";

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

//輸入檢查 6-20為正常字符

- (BOOL)inputCheck:(NSString*)passWord{

NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";

NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];

return [passWordPredicate evaluateWithObject:passWord];

}

- (void)didRegisterBackWithTag:(int)tag{

[self loginAlertWithReslut:tag];

}

//提交注冊

- (IBAction)clickRegister:(id)sender {

//輸入檢查

BOOL userNameCheck = [self inputCheck:self.userNameField.text];

BOOL userPswCheck = [self inputCheck:self.userPswField.text];

if (!userNameCheck | !userPswCheck) {

[self showAlertInfoWithTag:0 andMessage:@"用戶名或密碼出錯\n請輸入6-20位合法字符"];

return;

}

//取消鍵盤響應

[self.userNameField resignFirstResponder];

[self.userPswField resignFirstResponder];

ServerOperations *ops = [ServerOperations sharedInstance];

ops.delegate = self;

[ops registerWithUser:self.userNameField.text andPsw:self.userPswField.text];

}

//登錄提示

- (void)loginAlertWithReslut:(int)result{

switch (result) {

case 0:

//連接遠程數據庫失敗

[self showAlertInfoWithTag:0 andMessage:@"連接遠程數據庫失敗"];

break;

case 1:

//注冊成功

[self showAlertInfoWithTag:1 andMessage:@"注冊成功"];

break;

case 2:

//注冊失敗 用戶已經存在

[self showAlertInfoWithTag:2 andMessage:@"注冊失敗\n用戶已經存在"];

break;

default:

break;

}

}

//彈出提示框

- (void)showAlertInfoWithTag:(int)tag andMessage:(NSString*)message {

UIAlertController *alertVC =[UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];

if (tag == 1) {

[alertVC addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

[[NSUserDefaults standardUserDefaults] setObject:self.userNameField.text forKey:@"userName"];

[self.navigationController popViewControllerAnimated:YES];

}]];

}else{

[alertVC addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil]];

}

[self presentViewController:alertVC animated:YES completion:nil];

}

@end

向服務器發送的請求操作

整個操作寫成一個單例

#import

#import "CoreDataOperations.h"

//服務器地址

//static NSString* const kServerUrl = @"http://localhost/timetally/";

static NSString* const kServerUrl = @"http://timetallydemo.duapp.com/";

@protocol ServerOperationsDelegate

@optional

//登錄結果回調

- (void)didLoginBackWithTag:(int)tag;

//注冊結果回調

- (void)didRegisterBackWithTag:(int)tag;

//成功上傳

- (void)didUploadTallySuccessed;

//上傳失敗

- (void)didUploadTallyFaild;

@end

@interface ServerOperations : NSObject

@property(nonatomic,strong)id delegate;

+ (instancetype)sharedInstance;

//發送服務器請求加載數據

- (void)loadDataFormServer;

//上傳賬單至服務器

- (void)uploadTallyToServer;

//服務器刪除指定賬單

- (void)deleteTallyInServerWithIdentity:(NSString*)identity;

//登錄到服務器

- (void)loginWithUser:(NSString*)username andPsw:(NSString*)psw;

//注冊到服務器

- (void)registerWithUser:(NSString*)username andPsw:(NSString*)psw;

@end

#import "ServerOperations.h"

@implementation ServerOperations

static ServerOperations *instance = nil;

+ (instancetype)sharedInstance

{

return [[ServerOperations alloc] init];

}

+ (instancetype)allocWithZone:(struct _NSZone *)zone

{

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

instance = [super allocWithZone:zone];

});

return instance;

}

- (instancetype)init

{

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

instance = [super init];

});

return instance;

}

//發送服務器請求加載數據

- (void)loadDataFormServer{

NSMutableURLRequest *quest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[kServerUrl stringByAppendingString:@"showusertally.php"]]];

[quest setHTTPMethod:@"POST"];

//POST 用戶名

NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];

NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:userName,@"username", nil];

NSData *postData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];

[quest setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionTask *task = [session dataTaskWithRequest:quest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

//json解碼

NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSLog(@"server下載結果-----%@",dataStr);

if ([dataStr isEqualToString:@"0"]) {

return ;

}

NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

if (jsonArray.count != 0) {

[[CoreDataOperations sharedInstance] loadFromServerWithDataArray:jsonArray];

}

}];

[task resume];

}

//上傳賬單至服務器

- (void)uploadTallyToServer{

NSMutableURLRequest *quest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[kServerUrl stringByAppendingString:@"uploadtally.php"]]];

[quest setHTTPMethod:@"POST"];

//POST 信息

NSArray *postArray = [[CoreDataOperations sharedInstance] getAllTallyWithArray];

NSData *postData = [NSJSONSerialization dataWithJSONObject:postArray options:NSJSONWritingPrettyPrinted error:nil];

[quest setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionTask *task = [session dataTaskWithRequest:quest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

int flag = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] intValue];

NSLog(@"server上傳結果 %d",flag);

if (flag==1 || flag == 9) {

//寫入成功

for (NSDictionary *dict in postArray) {

[[CoreDataOperations sharedInstance] uploadServerSucceedWithIdentity:dict[@"identity"]];

}

dispatch_async(dispatch_get_main_queue(), ^{

if ([self.delegate respondsToSelector:@selector(didUploadTallySuccessed)]) {

[self.delegate didUploadTallySuccessed];

}

});

}else{

dispatch_async(dispatch_get_main_queue(), ^{

if ([self.delegate respondsToSelector:@selector(didUploadTallyFaild)]) {

[self.delegate didUploadTallyFaild];

}

});

}

}];

[task resume];

}

//登錄到服務器

- (void)loginWithUser:(NSString*)username andPsw:(NSString*)psw {

//創建URL請求

NSMutableURLRequest *quest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[kServerUrl stringByAppendingString:@"login.php"]]];

//post請求

[quest setHTTPMethod:@"POST"];

NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:username,@"username",psw,@"userpsw", nil];

//字典轉json

NSData *postData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];

[quest setHTTPBody:postData];

//建立連接

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionTask *task = [session dataTaskWithRequest:quest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

int result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] intValue];

NSLog(@"server登錄結果 %d ",result);

dispatch_async(dispatch_get_main_queue(), ^{

if ([self.delegate respondsToSelector:@selector(didLoginBackWithTag:)]) {

[self.delegate didLoginBackWithTag:result];

}

});

}];

[task resume];

}

//注冊到服務器

- (void)registerWithUser:(NSString*)username andPsw:(NSString*)psw{

//創建URL請求

NSMutableURLRequest *quest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[kServerUrl stringByAppendingString:@"register.php"]]];

//post請求

[quest setHTTPMethod:@"POST"];

NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:username,@"username",psw,@"userpsw", nil];

//字典轉json

NSData *postData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];

[quest setHTTPBody:postData];

//建立連接

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionTask *task = [session dataTaskWithRequest:quest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

int result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] intValue];

NSLog(@"server注冊結果 %d ",result);

//回到主線程

dispatch_async(dispatch_get_main_queue(), ^{

if ([self.delegate respondsToSelector:@selector(didRegisterBackWithTag:)]) {

[self.delegate didRegisterBackWithTag:result];

}

});

}];

[task resume];

}

//從服務器刪除賬單

- (void)deleteTallyInServerWithIdentity:(NSString*)identity{

//創建URL請求

NSMutableURLRequest *quest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[kServerUrl stringByAppendingString:@"deletetally.php"]]];

//post請求

[quest setHTTPMethod:@"POST"];

NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:identity,@"identity", nil];

//字典轉json

NSData *postData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];

[quest setHTTPBody:postData];

//建立連接

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionTask *task = [session dataTaskWithRequest:quest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

int result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] intValue];

if (result == 0) {

NSLog(@"%d server鏈接數據庫失敗",result);

}else if (result == 1){

NSLog(@"%d server刪除賬單成功",result);

}else if (result == 2){

NSLog(@"%d server刪除賬單失敗",result);

}

}];

[task resume];

}

@end

服務端部分

php新手 高手勿噴

文件結構

4a490eb17624

文件結構

其中index.php 和 useruploadrecords.php是web斷的登錄展示頁面

數據庫部分字段和表基本與客戶端相同可以看CREATE的代碼

代碼

配置文件

define('MYSQL_HOST','localhost');

define('MYSQL_USER','root');

define('MYSQL_PSW','');

define('MYSQL_DBNAME','TimeTally');

所有數據庫操作

require_once 'config.php';

/**鏈接并選擇數據表

* @param $table 鏈接表

* @return mysqli 鏈接link

*/

function connectDBandSelectTable($table) {

$con = mysqli_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PSW);

mysqli_set_charset($con,'utf8');

if ($con){

mysqli_select_db($con,MYSQL_DBNAME);

if(mysqli_num_rows(mysqli_query($con,"SHOW TABLES LIKE '".$table."'"))==0) {

if ($table == 'Tally'){

$sql = "CREATE TABLE $table

( id INT NOT NULL AUTO_INCREMENT ,

username VARCHAR(50) NOT NULL ,

date VARCHAR(50) NOT NULL ,

identity VARCHAR(1024) NOT NULL ,

typename VARCHAR(50) NOT NULL ,

income DOUBLE NOT NULL ,

expenses DOUBLE NOT NULL ,

timestamp DOUBLE NOT NULL ,

uploadtime TIMESTAMP NOT NULL,

PRIMARY KEY (id))";

mysqli_query($con,$sql);

}elseif ($table == 'Users'){

$sql = "CREATE TABLE $table

(id INT NOT NULL AUTO_INCREMENT,

username VARCHAR (100) NOT NULL ,

userpsw VARCHAR (100) NOT NULL ,

session INT NOT NULL DEFAULT 0,

PRIMARY KEY (id))";

mysqli_query($con,$sql);

}

}

}

return $con;

}

/**注冊

* @param $table 表

* @param $username 用戶名

* @param $userpsw 用戶密碼

* @return int 0:連接失敗 1:注冊成功 2:用戶已存在

*/

function register($table,$username,$userpsw){

$con = connectDBandSelectTable($table);

if ($con){

$isExist = existQuery($table,"username",$username);

if ($isExist == 2){

$sql = "INSERT INTO $table (username, userpsw) VALUES ('$username',MD5('$userpsw'))";

$result = mysqli_query($con,$sql);

if ($result){

//成功

return 1;

}

}else if ($isExist == 1){

//已存在

return 2;

}

//關閉數據庫

mysqli_close($con);

}

//連接數據庫失敗

return 0;

}

/**查詢字段是否存在

* @param $table 表名

* @param $field 查詢字段名

* @param $obj 查詢對象

* @return 0:連接失敗 1:存在 2:不存在

*/

function existQuery($table,$field,$obj){

$con = connectDBandSelectTable($table);

if ($con){

$sql = "SELECT * FROM $table WHERE $field = '$obj'";

$result = mysqli_query($con,$sql);

if (mysqli_num_rows($result) > 0){

return 1;

}else{

return 2;

}

}

return 0;

}

/**獲取該用戶下所有賬單

* @param $table 表名

* @param $user 用戶名

* @return int|string 0:連接失敗或無法查詢 string:json數組;

*/

function getUserTally($table,$user){

$con = connectDBandSelectTable($table);

if ($con){

$sql = "SELECT * FROM $table WHERE username = '$user'";

$arr = mysqli_query($con,$sql);

$num = mysqli_num_rows($arr);

if ($num > 0){

for ($i=0;$i

$results[] = mysqli_fetch_assoc($arr);

}

mysqli_close($con);

return json_encode($results);

}

}

//連接失敗或無法查詢

return 0;

}

/**登錄驗證

* @param $username 用戶名

* @param $userpsw 用戶密碼

* @return int 0:連接失敗 1:驗證成功 2:密碼錯誤 3:用戶不存在

*/

function verifyLogin($username,$userpsw){

//查詢用戶名是否存在

$table = 'Users';

$con = connectDBandSelectTable($table);

if ($con){

$sql = "SELECT * FROM $table WHERE username = '$username'";

$isExist = mysqli_query($con,$sql);

if (mysqli_num_rows($isExist) > 0) {

//存在并繼續驗證 密碼

$result = mysqli_fetch_array($isExist);

$psw = $result['userpsw'];

if (md5($userpsw) == $psw){

//密碼正確

return 1;

}else {

//密碼錯誤

return 2;

}

}else {

//用戶不存在

return 3;

}

mysqli_close($con);

}

//數據庫連接失敗

return 0;

}

/**上傳更新或新增賬單數據

* @param $table 寫入表名

* @param $tallyJson 傳入解析后的json

* @return int -1:數據庫連接失敗 0:沒有寫入 1:寫入成功 2:寫入失敗 9:更新數據

*/

function uploadTally($table,$tallyJson){

$con = connectDBandSelectTable($table);

$r = 0;

if ($con){

//根據json解析出來的數組的長度 更新對應identity數值

for ($i=0;$i

$identity = $tallyJson[$i]->identity;

$isExistSql = "SELECT * FROM $table WHERE identity LIKE '$identity'";

$isExisResult = mysqli_query($con,$isExistSql);

if (mysqli_num_rows($isExisResult) > 0){

$typename = $tallyJson[$i]->typename;

$income = $tallyJson[$i]->income;

$expenses = $tallyJson[$i]->expenses;

$timestamp = $tallyJson[$i]->timestamp;

$updateSql = "UPDATE $table

SET typename = '$typename',

income='$income' ,

expenses = '$expenses',

uploadtime = CURRENT_TIMESTAMP,

timestamp = '$timestamp'

WHERE identity = '$identity'";

mysqli_query($con,$updateSql);

$r = 9;

} else{

//沒有查詢到identity則進入新增

$typename = $tallyJson[$i]->typename;

$income = $tallyJson[$i]->income;

$expenses = $tallyJson[$i]->expenses;

$username = $tallyJson[$i]->username;

$date = $tallyJson[$i]->date;

$timestamp = $tallyJson[$i]->timestamp;

//mysql插入

$intoSql = "INSERT INTO $table

(id,username,date,identity,typename,income,expenses,timestamp,uploadtime)

VALUES (NULL, '$username', '$date','$identity','$typename','$income','$expenses','$timestamp',CURRENT_TIMESTAMP)";

$insertResult = mysqli_query($con,$intoSql);

if ($insertResult){

//新增成功

$r = 1;

}else{

//新增失敗

$r = 2;

}

}

}

mysqli_close($con);

}else{

//連接失敗

$r = -1;

}

return $r;

}

/**

* @param $table 表名

* @param $identity 需要刪除的標識

* @return int 0:鏈接數據庫失敗 1:刪除成功 2:刪除失敗

*/

function deleteTally($table,$identity){

$con = connectDBandSelectTable($table);

if ($con){

$sql = "DELETE FROM $table WHERE identity = '$identity'";

$result = mysqli_query($con,$sql);

if ($result){

return 1;

}else{

return 2;

}

}

mysqli_close($con);

return 0;

}

/**獲取post的json數據 并連接數據庫表

* @param $table 表名

* @return mixed json數據

*/

function getPostJsonValue($table){

//獲取post數據

$postValue = file_get_contents("php://input");

//json解析

$postJson = json_decode($postValue);

$currentTable = $table;

//連接并選擇數據庫

connectDBandSelectTable($currentTable);

return $postJson;

}

各個調用頁面

登錄

require_once 'dboperations.php';

//獲取post數據

$table = 'Users';

$postValue = getPostJsonValue($table);

//登錄驗證

$result = verifyLogin($postValue->username,$postValue->userpsw);

echo $result;

注冊

require_once 'dboperations.php';

//獲取post數據并連接數據庫表

$currentTable = 'Users';

$postJson = getPostJsonValue($currentTable);

//注冊

$result = register($currentTable,$postJson->username,$postJson->userpsw);

echo $result;

下載服務端數據

require_once 'dboperations.php';

$table = 'Tally';

$postValue = getPostJsonValue($table);

$reslut = getUserTally($table,$postValue->username);

echo $reslut;

上傳

require_once 'dboperations.php';

$table = 'Tally';

$postJson = getPostJsonValue($table);

$result = uploadTally($table,$postJson);

echo $result;

刪除

require_once 'dboperations.php';

$table = 'Tally';

$postValue = getPostJsonValue($table);

$reslut = deleteTally($table,$postValue->identity);

echo $reslut;

web端

首頁登錄

content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

Document

內容頁

content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

Document

require_once 'dboperations.php';

if (isset($_GET["username"]) && isset($_GET["userpsw"])){

$username = $_GET["username"];

$userpsw = $_GET["userpsw"];

}

$verifty = verifyLogin($username,$userpsw);

if ($verifty == 1){

$table = 'Tally';

$con = connectDBandSelectTable($table);

$sql = "SELECT * FROM $table WHERE username = '$username' ORDER BY uploadtime DESC ";

$res = mysqli_query($con,$sql);

echo "

歡迎用戶:$username
操作記錄上傳時間賬單類型支出收入

for ($i=0;$i

$resarray = mysqli_fetch_assoc($res);

$uploadtime = $resarray["uploadtime"];

$typename = $resarray["typename"];

$income= $resarray["income"];

$expenses = $resarray["expenses"];

?>

}

echo "

";

}elseif ($verifty == 2){

echo "";

}elseif ($verifty == 3){

echo "";

}

?>

Demo地址

4a490eb17624

github

簡書主頁

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/136802.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息