linux——使用数据库接口完成学生管理系统(2)

本文是关于使用C语言在Linux系统中构建学生管理系统的第二部分,主要实现了学生的注册、登录及信息修改功能。注册时需判断学生是否已注册,未注册则插入数据库待审核。登录验证账号密码,显示和修改信息的函数与管理员功能类似,但针对学生个人信息。代码中存在设计问题,实际应用中建议使用学号作为唯一标识进行登陆和注册。
摘要由CSDN通过智能技术生成

上一篇文章写了管理员的功能。这篇文章主要完善的是学生的功能。
学生的功能有两个:

  1. 学生注册
  2. 登录后显示个人的信息以及修改个人的部分信息。

这几个函数的实现方法都和前面的差不多。 所以这里主要都是代码。

首先学生的注册函数。
学生注册的时候要先判断该学生是否已经注册过。如果没有注册则将学生的信息插入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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值