上一篇文章写了管理员的功能。这篇文章主要完善的是学生的功能。
学生的功能有两个:
- 学生注册
- 登录后显示个人的信息以及修改个人的部分信息。
这几个函数的实现方法都和前面的差不多。 所以这里主要都是代码。
首先学生的注册函数。
学生注册的时候要先判断该学生是否已经注册过。如果没有注册则将学生的信息插入temp_info表格,等待管理员审核。如果注册过则提醒用户后退出。
#include "head.h"
int stu_register(struct student_info *stu_info, MYSQL *sql)
{
MYSQL_RES *res = NULL;
MYSQL_ROW row;
int rows;
int fields;
char query[128];
char ch;
system("clear");
printf("\n-------- student register --------\n");
printf("enter your name or enter 'quit' to quit: ");
scanf("%s",stu_info->name);
while(getchar()!='\n')
continue;
if(strcmp(stu_info->name,"quit") == 0)
return 0;
memset(query,0,sizeof(query));
sprintf(query, "select * from stu_login where name='%s'", stu_info->name);
//-------- 判断该用户是否已经注册 --------
mysql_real_query(sql,query,strlen(query));
res = mysql_store_result(sql);
rows = mysql_num_rows(res);
//----------------------------------------
//用户已经注册
if(rows == 1)
{
printf("\n>>>>>>>> You have already registered! <<<<<<<<\n");
sleep(2);
return 0;
}
//用户未注册
else
{
system("clear");
printf("\n>>>>>>> 中途可以输入'quit'退出 <<<<<<<\n");
printf("\nyour name: %s",stu_info->name);
printf("\nyour sno: ");
scanf("%s",stu_info->sno);
while(getchar()!='\n')
continue;
if(strcmp(stu_info->sno,"quit") == 0)
return 0;
printf("\nyour password: ");
scanf("%s",stu_info->password);
while(getchar()!='\n')
continue;
if(strcmp(stu_info->password,"quit") == 0)
return 0;
printf("\nyour city: ");
scanf("%s",stu_info->city);
while(getchar()!='\n')
continue;
if(strcmp(stu_info->city,"quit") == 0)
return 0;
memset(query,0,sizeof(query));
sprintf(query,"insert into temp_info value('%s','%s','%s','%s')",stu_info->sno,stu_info->name,stu_info->password,stu_info->city);
mysql_real_query(sql,query,strlen(query