加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLite学习笔记5

发布时间:2020-12-12 19:50:31 所属栏目:百科 来源:网络整理
导读:1、 用 DW 画了一个登录界面 login.html 源码如下: html xmlns="http://www.w3.org/1999/xhtml" head titleTL 智能家居管理平台 2009/title /head body p 欢迎光临智能家居管理平台 /p form id="form1" name="form1" method="post" action="/cgi-bin/login.

1、DW画了一个登录界面


login.html源码如下:


<html xmlns="http://www.w3.org/1999/xhtml">


<head>


<title>TL智能家居管理平台2009</title>


</head>



<body>


<p>欢迎光临智能家居管理平台</p>


<form id="form1" name="form1" method="post" action="/cgi-bin/login.cgi">


<p>


<label for="user_name">用户名:</label>


<input name="user_name" type="text" id="user_name" maxlength="50" />


</p>


<label for="passwd">密码:</label>


<input name="passwd" type="password" id="passwd" maxlength="20" />


<label for="submit"></label>


<input type="submit" name="submit" id="submit" value="提交" />


<label for="abord"></label>


<input type="reset" name="abord" id="abord" value="重置" />


</form>


<p>&nbsp;</p>


</body>


</html>


呵呵界面有点难看,不过先实现这个功能再说啦


2、编写相应的CGI程序:


login.c


/*登录查询*/


#include <stdio.h>


#include "sqlite3.h"


#include "cgic.h"


int


callback(void *param,int column_num,char **rc,char **column_name);/*sqlite3的回调函数*/


hand_username(const char *database_filename);


/*处理用户名的函数*/


char username[51];


cgiMain()


{


cgiHeaderContentType("text/html");


fprintf(cgiOut,"<html><head>n");






cgiFormStringNoNewlines("user_name",username,51);


/*获得用户输入域的数据*/


hand_username("/root/FamilyGate/homeg");/*database path*/



return 0;


}


hand_username(const char *database_filename)


int query_rc;/*查询结果*/


sqlite3 *db = NULL;/*数据库连接指针*/


char *error_msg = 0;/*错误信息指针*/


char *sql_statement = "SELECT user_name FROM users";/*SQL语句*/


if(sqlite3_open(database_filename,&db))


{


/*打开数据库失败*/


打开数据库失败!n %s",sqlite3_errmsg(db));


sqlite3_close(db);


}else


query_rc = sqlite3_exec(db,sql_statement,callback,&error_msg);


if(query_rc==0)


不是家庭成员!<br />",username);


if(query_rc && (query_rc!=4))


printf("code is:%d<br />",query_rc);



}


/*注意如果数据库有多条记录的话,每当查出一条记录就会调用一次回调函数*/


if(strcmp(rc[0],username)==0)


/*我只查询user_name这一列,所以这列的数据是放在rc[0]中的,直接拿来比较*/


欢迎:%s<br />",宋体"> return 1;/*the call back must have a return value,or the sqlite3_exec() will return 4*/


/*若回调函数没有返回0值,则sqlite3_exec()将返回错误码:4,即回调函数中止*/


/*对于复杂的情况可以在回调函数中将记录结果保存到一个指针数组中,待查询完毕再做相关的处理*/


return 0;


3、在浏览器中输入服务器的IP和访问的网址:


192.168.44.128/html/login.html


随便填写一个用户名,然后提交,程序将判断是否是设定的用户。


后期的处理是,如果是合法用户则跳到管理页面,不是合法用户则打印出错提示。同时还要解决用户名的客户端认证,只允许用户输入英文和数字,以及密码的MD5加密,以后将同时检查用户名和密码是否合法,合法则进入管理页面。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读