系统参数配置 配置选项
#include #include #include #include #include #include #include "cgic.h" #include "sqlite3.h" #define SQL_SIZE 256 int cgiMain(int argc, char **argv){char name[64];char age[4];char sex[8];char company[64];char profession[16];char idnumber[24];char qq[24];char email[64];char telephone[16];//回显信息到HTML网页cgiHeaderContentType("text/html"); printf("
");printf("
");//获取表单中的name的值,存入name缓冲区if(cgiFormString("name", name, sizeof(name)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function name failed");exit(-1);}printf("姓名:%s
",name);printf("
");if(cgiFormString("age", age, sizeof(age)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function age failed");exit(-1);}printf("年龄:%s
",age);printf("
");if(cgiFormString("sex", sex, sizeof(sex)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function sex failed");exit(-1);}printf("性别:%s
",sex);printf("
");if(cgiFormString("company", company, sizeof(company)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function company failed");exit(-1);}printf("单位:%s
",company);printf("
");if(cgiFormString("profession", profession, sizeof(profession)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function profession failed");exit(-1);}printf("职业:%s
",profession);printf("
");if(cgiFormString("idnumber", idnumber, sizeof(idnumber)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function idnumber failed");exit(-1);}printf("身份证号码:%s
",idnumber);printf("
");if(cgiFormString("email", email, sizeof(email)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function email failed");exit(-1);}printf("Email:%s
",email);printf("
");if(cgiFormString("telephone", telephone, sizeof(telephone)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function telephone failed");exit(-1);}printf("Telepone:%s
",telephone);printf("
");if(cgiFormString("qq", qq, sizeof(qq)) != cgiFormSuccess){fprintf(stderr, "cgiFormString function qq failed");printf("cgiFormString function qq failed");exit(-1);}printf("QQ号码:%s
",qq);printf("
");printf("
");printf("
");//数据存储到数据库sqlite3 *db;int result;result = sqlite3_open("person.db", &db); if(result != SQLITE_OK) { printf("Fail to sqlite3_open person.db: %s.
", sqlite3_errmsg(db)); exit(-1); }char *errmsg;char sql[SQL_SIZE];bzero(sql, SQL_SIZE);strcpy(sql, "CREATE TABLE person(ID varchar(24) PRIMARY KEY,name text,age text, sex text, company text, profession text, qq text, email text, telephone text);"); if(sqlite3_exec(db, sql, NULL, NULL, &errmsg) != 0) { printf("Fail to exec sql: %s.
", errmsg); printf("
%s
",sql); exit(-1); } bzero(sql, SQL_SIZE);strcpy(sql, "INSERT INTO person values('1234567899876543', '天山老妖', '30', 'boy', '天山', '嵌入式工程师', '123455678', 'hello@qq.com', '123344');");if(sqlite3_exec(db, sql, NULL, NULL, &errmsg) != 0) { printf("Fail to exec sql: %s.
", errmsg); printf("
%s
",sql); exit(-1); }result = sqlite3_close(db); if(result != 0) { fprintf(stderr, "Fail to sqlite3_open person.db : %s.
", sqlite3_errmsg(db)); exit(-1); }return 0;}
注意:程序需要使用CGIC库的接口函数、SQLite数据库的接口函数,因此编译时需要包括相关文件sqlite3.c、cgic.c,同时需要SQLite数据库的动态链接库支持,因此需要将编译后SQLite数据库的lib目录下的文件拷贝到交叉编译工具的lib目录中,编译时需指定-lsqlite3。编译程序:arm-linux-gcc -o config.cgi config.c sqlite3.c cgic.c -lsqlite3将编译后的config.cgi程序拷贝到开发板的www目录下的cgi-bin目录打开客户端浏览器:http://192.168.6.210/config.html输入配置信息,提交将会显示配置的内容信息查看数据库中的内容:sqlite> select * from person;1234567899876543||30|boy|||123455678|hello@qq.com|123344sqlite>