html - 解析 HTML 表单数据

标签 html c cgi

当我简单地打印查询时,我得到:

一=1&二=2&三=3&四=3&五=3&六=3

还是不行!!!我快要疯了。

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

int main(void){

    char *data;
    float prices[] = {1, 2, 3, 4, 5, 6};
    int a, b, c, d, e, f;

    printf("%s%c%c\n",
    "Content-Type:text/html;charset=iso-8859-1",13,10);

    printf("<title>Bill</title>\n");
    printf("<h3 align=center >Bill</h3>\n");

    data = getenv("QUERY_STRING");

    if(data == NULL){
            printf("<p>Error!</p>");
    } else {
    printf("%s", data);
    sscanf(data, "one=%d&two=%d&three=%d&four=%d&five=%d&six=%d", &a, &b, &c, &d, &e,       &f);
    }

return 0;

}

最佳答案

Is there an easy and not error prone way to deal with this issue?

是的;存在各种C库,例如cgicC CGI ,处理像这样的常见 CGI 任务。 (如果这些都不符合您的口味,请尝试 Googling "C CGI library" 其他选项。)

关于html - 解析 HTML 表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9899440/

相关文章:

html - Html 表格列内的 div 之间不需要的间距

linux - 像 CGI 一样在 linux apache 中运行 EXE 文件

python - 带有 python cgi 的 Javascript 未给出预期结果

html - CSS 和表格。空框?

html - CSS/Javascript 如何像在 IE7+ 中那样在 Firefox 中制作这个背景位置影片?

c - 如何使用c代码读取复杂的lua表

c++ - 接收所有使用 C 套接字发送的数据

python - 在 chroot 环境 OpenBSD 中配置设备

jQuery 空函数和 html 函数

c++ - 在同一行上使用 malloc 创建两个数组