Update.c

This code is executed when the Client wants to update the quantity of any item on his Shopping list.

Source code of Delete.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 result;

char a1[30];char b[30];
char c[30];char d[30];
char e[30];char f[30];
char g[30];char h[30];char r[30];char hh[10];

// 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];

char item[5],new_qtty[5];
SDWORD cba,cbb,cbc,cbd,cbe,cbf,cbt; // Last parameter of SqlGetData


int cgiMain()
{
int len,i;
long n,m,TEMP=0;
cgiHeaderContentType("text/html");
fprintf(cgiOut,"<HTML><HEAD>\n");
fprintf(cgiOut,"<TITLE> UPDATED FINAL LIST </TITLE></HEAD>");
fprintf(cgiOut,"<body><h2><font color='red'> YOUR UPDATED SHOPPING CART CONTAINS :</font></h2><br><br>");

cook=getenv("HTTP_COOKIE");
sprintf(IDN1,"%s",cook);

cgiFormStringNoNewlines("prod_id",PROD_ID,5); // Capture Product ID here
len=strlen(PROD_ID);
for(i=0;i<len;i++)
{
PROD_ID[i]=toupper(PROD_ID[i]);
}

cgiFormStringNoNewlines("old",QTY,5); // Capture previous value of Reqd. Item

cgiFormStringNoNewlines("new",new_qtty,5); // Capture new value of Reqd Item.


// odbc code starts

// Code for updating database
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,"PRODS",-3,0,0,0,0);
SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"UPDATE S SET QTY='%s' WHERE PROD_ID='%s' AND QTY='%s'",&new_qtty,&PROD_ID,&QTY);
SQLExecDirect(hstmt,aa, -3);
SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 1
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);


// CODE FOR CALCULATING UPDATED COST OF PRODUCT

SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,"COST",-3,0,0,0,0);
SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"SELECT COST_ITEM FROM T WHERE PROD_ID='%s'",&PROD_ID);
SQLExecDirect(hstmt,aa, -3);
SQLFetch(hstmt);
SQLGetData(hstmt,1,SQL_C_CHAR,hh,sizeof(hh),&cbt);

n=atol(hh);
m=atol(new_qtty);
TEMP=n*m;
ltoa(TEMP,Cost,10);
SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 2
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);

// CODE FOR RETRIVING UPDATED DATA
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,"PRODS",-3,0,0,0,0);

SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"UPDATE S SET TOT_COST='%s' WHERE IDNO='%s' AND PROD_ID='%s' AND QTY='%s'",&Cost,&IDN1,&PROD_ID,&new_qtty);
SQLExecDirect(hstmt,aa, -3);
SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 3

SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"SELECT * FROM S WHERE IDNO='%s'",&IDN1);
result=SQLExecDirect(hstmt,aa, -3);
sprintf(aa,"result=%d",result);
TEMP=0;
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);

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> ");
fprintf(cgiOut, "<form name='modify' method='post' action='/cgi-shl/invoice.exe'>");
fprintf(cgiOut, "<input type='submit' name='bb' value='EXIT'>");
fprintf(cgiOut, "</form>");


SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 2
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
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 .

This program accepts the Product ID along with the previous quantity and update the database to the value of new quantity provided by the Client .Here 3 sets of ODBC connections come into picture.

The first set of ODBC connection will update the quantity column of the User's Shopping Cart (S.dbf).
The second set of ODBC connection will calculate the updated cost of the Updated Item ,by retrieving the Cost per item of that particular item from T.dbf database file.
Lastly, the final set of ODBC connection will retrieve the modified Shopping Cart details (S.dbf) ,back to the user ,in an HTML layout .

 

BACK TO MAIN PAGE

cooky.c:

cooky1.c :

Recall.c :

Delete.c:

Invoice.c :

Back to Homepage