[c]代码库
#include <stdio.h>
#include <string.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int i;
printf("<tr>");
for(i=0; i<argc; i++){
printf("<td>%s</td>", argv[i] ? argv[i] : "NULL");
}
printf("</tr>");
return 0;
}
int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("students.db", &db);
if( rc ){
printf("Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return(1);
}
printf("Content-Type:text/html\n\n");
printf("<HTML>\n");
printf("<HEAD><TITLE>Communication Records List</TITLE></HEAD>");
printf("<BODY>");
/*printf("<table border=\"1\" bordercolor=\"#FF0000\" style=\"margin-left:550px; margin-top:50px\"><tr><td>Contacts</td></tr></table>");
*/
printf("<table border=\"1\" bordercolor=\"#FF0000\" style=\"margin-left:500px; margin-top:50px\"> Contacts<tr><td>number</td><td>Name</td><td>class</td></tr>");
char *data;
data = getenv("QUERY_STRING");
int class;
char buf0[50];
char buf1[50];
char *n,*m;
n=buf0;
m=buf1;
if(data == NULL)
{
printf("<P>ERROR</p>");
}
else
{
sscanf(data,"%[^&]&%s",buf0,buf1);
}
//char *sql = "select * from contacts where class=";
//sql=strcat(sql,buf0);
char sql[50];
//char *ch1=" or ";
sprintf(sql,"select * from contacts where %s or %s",n,m);
//char *ch2=strcat(m,ch1);
//char *ch3=strcat(ch2,n);
char *sqll=sql;
//printf("<tr><td>%s</td></tr>",sqll);
//char class1 = class;
//char *sql;
//sql=strcat("select * from contacts where class=",class1);
//printf("<tr><td>%s</td></tr>",class1);
rc = sqlite3_exec(db,sql, callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
printf("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
printf("</table><a href=\"query.html\">Come back!</a></body></html>");
sqlite3_close(db);
return 0;
}
[代码运行效果截图]
[源代码打包下载]
by: 发表于:2017-08-14 11:28:29 顶(0) | 踩(0) 回复
??
回复评论