0

Why can't I insert to my database? I've read multiple threads regarding this error and all of their problems were that they forgot calling open for the database. Help?

sqlite3 *data;
sqlite3_stmt *res;
char *errMSG;
int sql=0;
const char *tail;
char insert[100];

sql = sqlite3_open("pokemon.db", &data);
if(sql){
    puts("Can't open database");
    exit(0);
}

sprintf(insert, "Insert into Players values('%s','%s',1, 0,%d,%d,%d,0,0,'%s');", name, species, HP, ATTK, DEF, key);

sql = sqlite3_prepare_v2(data, insert, 1000, &res, &tail);
printf("%d\n",sql);
sqlite3_step(res);
sqlite3_finalize(res);
sqlite3_close(data);

printf("You have successfully captured a new Pokemon!<br>");
printf("%s", sqlite3_errmsg(data));
printf("<form action=start.cgi><input type=submit value='Go back to Home Page!'></form>");


printf("</body></html>");
return 0;
4

1 回答 1

0

在您对 的调用中sqlite3_errmsg(data),数据库连接data已经关闭。

我怀疑这是无效的——并且这个无效的调用sqlite3_errmsg()是错误字符串所指的,而不是任何早期的错误。

于 2016-07-13T18:08:48.323 回答