真·第一次作业

本文介绍了一个使用CGI进行表单数据处理的示例,并展示了如何通过模板引擎向页面传递数据,包括用户信息及商品列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!doctype html>

登陆 点我传数据 用户名:
密码:
男 女
描述:
民族: 临沂 北京 河南

char username[256];
char pwd[250];
char desc[256];
char sex[3];
char quyu[256];

if(cgiFormSubmitClicked(“login”) == cgiFormSuccess){
cgiFormString(“username”,username,sizeof(username));
cgiFormString(“pwd”,pwd,sizeof(pwd));
cgiFormString(“sex”,sex,sizeof(sex));
cgiFormString(“desc”,desc,sizeof(desc));
cgiFormString(“quyu”,quyu,sizeof(quyu));

cgiHeaderContentType("text/html;charset=gbk");
//printf(username);
//printf(pwd);
fprintf(cgiOut,"<html><head></head><body>");
fprintf(cgiOut,"用户名:%s,性别:%s",username,quyu);
fprintf(cgiOut,"</body></html>");
return 0;

}
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include"cgic.h"

int cgiMain(){
char model [32]={0};
char fun[32]={0};
if(cgiFromString(“model”,model,sizeof(model))!=cgiFromSuccess){
cgiHeaderContentType(“test/html;charset=gbk”);
printf(“modle参数必传”);
return 0;
}

if(cgiFromString(“fun”,fun,sizeof(fun))!=cgiFromSuccess){
cgiHeaderContentType(“text/html;)charset=gbk”
};
printf(“fun参数必传”);
return 0;
}
if(strcmp(model,“user”)==0){
if(strcmp(fun,“toLogin”)==0){
cgiHeaderLocation(“login.html”);
}
else if(strcmp(fun,“toRegister”)==0){
cgiHeaderLocation(“register.html”);
}
else if(strcmp(fun,“login”)==0){
char username[256];
char pwd[250];
cgiFormString(“username”,username,sizeof(username));
cgiFormString(“pwd”,pwd,sizeof(pwd));
//查询数据库对比用户名密码
if(strcmp(username,“zq”)==0 && strcmp(pwd,“123”)==0){
cgiHeaderContentType(“text/html;charset=gbk”);
printf(“登录成功”);
return 0;
}
else{
cgiHeaderContentType(“text/html;charset=gbk”);
printf(“用户名或密码错误”);
return 0;
}
}
}
<!doctype html>

无标题文档
您的姓名是<TMPL_VAR name="realname"/>,您的年龄是<TMPL_VAR name="age"/>岁
<br/>
<p>列表</p>
<ul>
	<TMPL_LOOP name="goods">
    	<li>商品名称,<TMPL_VAR name ="goodname">,价格,<TMPL_VAR name="price">				<li>
    </TMPL_LOOP>
</ul>
#include

int cgiMain(){
cigHeaderContentType(“text/html;charset=gbk”);
//往前台index.html传数据并跳转
TMPL_varlist *varlist=0;
TMPL_loop *loopGoods=0;
varlist=TMPL_add_var(varlist,“realname”,“赵琦”,“age”,“80”,0);
//循环的列表数据
loopGoods=TMPL_add_varlist(loopGoods,TMPL_add_var(0,“goodname”,“裤子”,“price”,“20”,0));
loopGoods=TMPL_add_varlist(loopGoods,TMPL_add_var(0,“goodname”,“褂子”,“price”,“20”,0));
varlist=TMPL_add_loop(varlist,“goods”,loopGoods);
Tmpl_write(“index.html”,0,0,varlist,cgiOut,cgiOut);
Tmpl_fre_varlist(varlist);
return 0;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值