Recall.c
This code is executed when the Client clicks on the View Shopping Cart button provided on the Shopping Mall. This code will recall the contents of the Shopping Cart of the Client .
Source code of Recall.c
#include <stdio.h>
#include <cgic.h>
#include <windows.h>
#include <string.h>
#include <sql.h>
#include <sqlext.h>
#include <dos.h>
#include <ctype.h>
// POINTER DECLARATIONS FOR ODBC CONNECTION
void *henv;
void *hdbc;
void *hstmt;
char a[100];char aa[100];char bb[100];int qq;
int result;
char a1[30];char b[30];
char c[30];char d[30];
char e[30];char f[30];
// BUFFER DECLARATIONS FOR FUNC LIST
char IDN1[6]; // for cookies
char *cook; // for cookies
char IDN[5];
char PROD_ID[10];
char PROD_DESC[10];
char QTY[10];
char COST_ITEM[5];
char TOT_COST[8];
char Cost[10];
long n,TEMP=0;
SDWORD cba,cbb,cbc,cbd,cbe,cbf,cbg,cbh,cbr; // Last
parameter of SqlGetData
int cgiMain()
{
cgiHeaderContentType("text/html");
fprintf(cgiOut,"<HTML><HEAD>\n");
fprintf(cgiOut,"<TITLE> FINAL LIST
</TITLE></HEAD>");
fprintf(cgiOut,"<body><h2><font
color='red'> YOUR SHOPPING CART CONTAINS
:</font></h2><br>");
cook=getenv("HTTP_COOKIE");
sprintf(IDN1,"%s",cook);
// odbc code starts
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,"PRODS",-3,0,0,0,0);
SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"SELECT * FROM S WHERE
IDNO='%s'",&IDN1);
SQLExecDirect(hstmt,aa, -3);
result=SQLFetch(hstmt);
while (result != SQL_NO_DATA_FOUND)
{
SQLGetData(hstmt, 1,SQL_C_CHAR,a1,sizeof(a1),&cba);
SQLGetData(hstmt, 2,SQL_C_CHAR,b,sizeof(b),&cbb);
fprintf(cgiOut, "<B>PROD_ID :</B> %s ", b);
SQLGetData(hstmt, 3,SQL_C_CHAR,c,sizeof(c),&cbc);
fprintf(cgiOut, "<B>PROD_DESC:</B> %s ",
c);
SQLGetData(hstmt, 4,SQL_C_CHAR,d,sizeof(d),&cbd);
fprintf(cgiOut, "<B>QTY:</B> %s ", d);
SQLGetData(hstmt, 5,SQL_C_CHAR,e,sizeof(e),&cbe);
fprintf(cgiOut, "<B>COST_ITEM :</B> %s
<BR>", e);
SQLGetData(hstmt, 6,SQL_C_CHAR,f,sizeof(f),&cbf);
fprintf(cgiOut, "<B>TOT_COST :</B> Rs
%s<BR><BR>", f);
n=atol(f);
TEMP=TEMP+n;
ltoa(TEMP,Cost,10);
result=SQLFetch(hstmt);
}
fprintf(cgiOut, "\n<B>FINAL COST =Rs %s
</B><br><br>\n", Cost);
SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 4
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
fprintf(cgiOut, "<form name='modify' method='post'
action='/cgi-shl/delete.exe'>");
fprintf(cgiOut, "Enter PRODUCT ID of Item to be deleted
:");
fprintf(cgiOut, "<input type='text' name='prod_id'
size='4' maxlength='4' ><br>");
fprintf(cgiOut, "<input type='submit' name='bb'
value='Delete Item'>");
fprintf(cgiOut, "</form>");
fprintf(cgiOut, "<form name='modify' method='post'
action='/cgi-shl/update.exe'>");
fprintf(cgiOut, "Enter PRODUCT ID of Item to be updated
:");
fprintf(cgiOut, "<input type='text' name='prod_id'
size='4' maxlength='4'><br>");
fprintf(cgiOut, "Enter previous value of Qty
ordered:");
fprintf(cgiOut, "<input type='text' name='old' size='4'
maxlength='4' ><br>");
fprintf(cgiOut, "Enter new value of Qty required:");
fprintf(cgiOut, "<input type='text' name='new' size='4'
maxsize='4' ><br>");
fprintf(cgiOut, "<input type='submit' name='aa'
value='Update Item'><br>");
fprintf(cgiOut, "</form>");
fprintf(cgiOut, "<BR>");
fprintf(cgiOut, "<a href='/listof.htm'>BACK TO MAIN
SHOPPING PAGE </a><BR><br>");
fprintf(cgiOut, "<form name='modify' method='post'
action='/cgi-shl/invoice.exe'>");
fprintf(cgiOut, "<input type='submit' name='bb'
value='EXIT'>");
fprintf(cgiOut, "</form>");
fprintf(cgiOut, "</BODY></HTML>\n");
return 0;
}// END OF MAIN
PROGRAM EXPLANATION :Firstly, you have to add cgic.c and cgic.h to your project workspace in Visual C++. These files have been provided in the downloaded files link .
cook = getenv("HTTP_COOKIE");
This function retrieves the cookie from the environment variable ,HTTP_COOKIE , and stores it in the variable cook .This is done so as to distinguish one client from another ,in case of multiple connections to the Server .
The ODBC connection explanation has already been provided in cooky.c. This connection will retrieve the Client's shopping details in accordance with his cookie number.
result=SQLFetch(hstmt);
This function fetches a row of data from the specified database.After each call to SQLFetch , the cursor is positioned at the next row in the database.After the last row in the database is fetched ,this function will return SQL_NO_DATA_FOUND . This condition is checked for exiting out of the while loop.
SQLGetData(hstmt, 1,SQL_C_CHAR,a1,sizeof(a1),&cba);
This function returns data for a single column of the current row.The function SQLFetch must be called before calling this function .The second parameter in this function specifies the column number in the database.The retrieved data is stored in a buffer which is the fourth parameter of the function .
After retrieving the contents of the client's shopping Cart ,he is also provided the option to modify the same,in the form of update /delete buttons .
Delete.c :
Update.c :