C / CGI文件的内部服务器错误,服务器错误:“脚本标头过早结束”

时间:2012-03-28 23:37:02

标签: html c cgi

我正在编写一个从html表单中获取数据的CGI文件。我已将权限设置为755,文件编译(在C中编写脚本),路径是正确的。我还是打不开页面!我不知道该怎么做......

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

int main(){

    char *data;
    float prices[] = {100, 1000, 2500, 200, 150, 3000};
    float subtotals[6];
    int q[6] = {0}; // initialize an array of 0s for quantities read from query string
    float grandTotal = 0;

    data = getenv("QUERY_STRING");
    sscanf(data, "one=%d&two=%d&three=%d&four=%d&five=%d&six=%d", &q[0], &q[1], &q[2], &q[3], &q[4], &q[5]);

    printf("Content-type: text/html\n\n");
    printf("<html>\n");
    printf("<head>");
    printf("<style type=\"text/css\">");
    printf("body { background-image: -moz-linear-gradient(bottom left, #70E6B3 0%%, #4F8054 100%%); }");
    printf("h1 {color:black; text-align:center; font-size:40px; font-weight:bold}");
    printf("h2 {color:red; text-align:center; font-size:30px; font-weight:bold}");
    printf("p {font-family:\"Helvetica\"; font-size:15px; color:white }");
    printf("</style>");
    printf("</head>");

    printf("<body>\n");
    printf("<h1>Your Bill</h1>\n");

    int i;
    for(i=0; i<6; i++){
            if(q[i]>0){
            printf("<p> Quantity: %d \n", q[i]);
            printf("Price: $ %f\n", prices[i]);
            printf("Total:$ %f </p><br>\n", q[i]*prices[i]);
            subtotals[i]=q[i]*prices[i];
            grandTotal=subtotals[i];
            }
    }

    printf("<h2>GRAND TOTAL $ %f</h2>", grandTotal);
    printf("</body>\n");
    printf("</html>\n");

    return 0;
}

0 个答案:

没有答案