login ---> sqlite--html---cgi(code)

//login.c


#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <cgi.h>

int rscallback(void *p, int argc, char **argv, char **argvv)
{
	*(int *)p = 0;//根据查询结果改变empty的值

	return 0;
}

int main()
{
	int ret;
	sqlite3 *db;
	char *sql = NULL;
	int empty = 1;
	char *err = NULL;

	cgi_init();
	cgi_process_form();

	ret = sqlite3_open("user.db", &db);
	if(ret != SQLITE_OK)
	{
		printf("Content-Type:text/plain\r\n\r\n");
		printf("database open error!\n");
		cgi_end();
		exit(1);
	}

	if((!cgi_param("UserName")) || (!cgi_param("password")))
	{
		printf("Content-Type:text/plain\r\n\r\n");
		printf("username and password must be entered!\n");
		sqlite3_close(db);
		cgi_end();
		exit(1);
	}
	else
		sql = sqlite3_mprintf("select * from user where username=%Q and password=%Q;", cgi_param("UserName"), cgi_param("password"));
		//sql = sqlite3_mprintf("select * from user where username=%Q and password=%Q;", "akaedu", "123");

	ret = sqlite3_exec(db, sql, rscallback, ∅, &err);
	if(ret != SQLITE_OK)
	{
		fputs(err, stderr);
		sqlite3_close(db);
		cgi_end();
		exit(1);
	}
	if(empty)//登录失败
	{
		cgi_redirect("/login_err.html");
	}
	else //登录成功
		cgi_redirect("/login_ok.html");

	sqlite3_close(db);
	cgi_end();

	return 0;
}


login.html

<html>
<head> <meta http-equiv="content-type" content="text/html;charset=UTF-8"></head>
<body>
<table width="100%" height="100%" border="0">
	<tr><td align=center valign=bottom>
			<img src="/images/admin_main_img_help.gif">
	</td></tr>
	<tr><td align=center valign=top>
	<form action='/cgi-bin/login.cgi' method=POST>
	<table border="0" cellpadding=0 cellspacing=0>
		<tr align=center valign=middle style="height: 49px">
		<td>
			<b>用户名:</b><input type='text' name='UserName' size=50><br>
			<b>密  码:</b><input type='password' name='password' size=50>
		</td>
		<td><input type="submit" value=" " style="background-image: url(/images/admin_login.gif);border: none;cursor: hand;width:85px;height:49px"><!--input type="submit" value="登录" style="height: 49px;width: 85px"-->
		</td>
		</tr>
	</table>
	</form>
	<embed src="/music/1.mp3" hidden="true" autostart="true" loop="true">
	</td></tr>
</table>
</body>

</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值