Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

mvahes / Lennubroneerimis_tarkvara

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Lennubroneerimis_tarkvara
  • addflights.c
Find file
BlameHistoryPermalink
  • karade's avatar
    Add new file · 76a35155
    karade committed 2 years ago
    76a35155
addflights.c 1.17 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
void AddFlightDest(MYSQL* con)
{
	char dest[STR_MAX];
	char dot[STR_MAX];
	int seats = 72;
	char flightNum[STR_MAX];
	char query[1024];
	
	
	
	
	//kontroll kas sama lennunumbriga on juba moni lend
	//muud asjad ei vaja kontrolli aga kuupäeva küsimises peaks formaadi
	//näide olema
	while(1)
	{
		puts("Enter flight number for new flight");
		scanf("%s", flightNum);
		
		sprintf(query, "SELECT flightNum FROM Flights WHERE flightNum = '%s'"
			,flightNum);
		
		if(mysql_query(con, query)){
			printf("Error checking if flightNum exists %s\n", mysql_error(con));
			exit(EXIT_FAILURE);
		}
		MYSQL_RES *result = mysql_store_result(con);
		MYSQL_ROW row;
		row = mysql_fetch_row(result);
		
		if(strcmp(row[0],flightNum) == 0)
		{
			puts("Flight number already exists, choose another");
		}
		else
			break;
	}
	

    
    sprintf(query, "INSERT INTO flights (destination, time" 
		"seats, flightNum) VALUES ('%s', '%s',%d '%s',);"
		,dest, dot, seats, flightNum);
		
	
		
    if (mysql_query(con, query)) { //päring serverile
        printf("Error inserting user into database: %s\n", mysql_error(con));
        exit(EXIT_FAILURE);
    }
    else
    {
		//Õnnestus teade'
		
	}
    
	
	
}